MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlDOMWrapNSNormDeclareNsForced

Function xmlDOMWrapNSNormDeclareNsForced

ThirdParty/libxml2/vtklibxml2/tree.c:8473–8531  ·  view source on GitHub ↗

* xmlDOMWrapNSNormDeclareNsForced: * @doc: the doc * @elem: the element-node to declare on * @nsName: the namespace-name of the ns-decl * @prefix: the preferred prefix of the ns-decl * @checkShadow: ensure that the new ns-decl doesn't shadow ancestor ns-decls * * Declares a new namespace on @elem. It tries to use the * given @prefix; if a ns-decl with the given prefix is already existent * on @ele

Source from the content-addressed store, hash-verified

8471* and internal errors.
8472*/
8473static xmlNsPtr
8474xmlDOMWrapNSNormDeclareNsForced(xmlDocPtr doc,
8475 xmlNodePtr elem,
8476 const xmlChar *nsName,
8477 const xmlChar *prefix,
8478 int checkShadow)
8479{
8480
8481 xmlNsPtr ret;
8482 char buf[50];
8483 const xmlChar *pref;
8484 int counter = 0;
8485
8486 if ((doc == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE))
8487 return(NULL);
8488 /*
8489 * Create a ns-decl on @anchor.
8490 */
8491 pref = prefix;
8492 while (1) {
8493 /*
8494 * Lookup whether the prefix is unused in elem's ns-decls.
8495 */
8496 if ((elem->nsDef != NULL) &&
8497 (xmlTreeNSListLookupByPrefix(elem->nsDef, pref) != NULL))
8498 goto ns_next_prefix;
8499 if (checkShadow && elem->parent &&
8500 ((xmlNodePtr) elem->parent->doc != elem->parent)) {
8501 /*
8502 * Does it shadow ancestor ns-decls?
8503 */
8504 if (xmlSearchNsByPrefixStrict(doc, elem->parent, pref, NULL) == 1)
8505 goto ns_next_prefix;
8506 }
8507 ret = xmlNewNs(NULL, nsName, pref);
8508 if (ret == NULL)
8509 return (NULL);
8510 if (elem->nsDef == NULL)
8511 elem->nsDef = ret;
8512 else {
8513 xmlNsPtr ns2 = elem->nsDef;
8514 while (ns2->next != NULL)
8515 ns2 = ns2->next;
8516 ns2->next = ret;
8517 }
8518 return (ret);
8519ns_next_prefix:
8520 counter++;
8521 if (counter > 1000)
8522 return (NULL);
8523 if (prefix == NULL) {
8524 snprintf((char *) buf, sizeof(buf),
8525 "ns_%d", counter);
8526 } else
8527 snprintf((char *) buf, sizeof(buf),
8528 "%.30s_%d", (char *)prefix, counter);
8529 pref = BAD_CAST buf;
8530 }

Callers 2

xmlDOMWrapAdoptAttrFunction · 0.85

Calls 3

xmlNewNsFunction · 0.85

Tested by

no test coverage detected