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

Function xmlSearchNsByNamespaceStrict

ThirdParty/libxml2/vtklibxml2/tree.c:8308–8394  ·  view source on GitHub ↗

* xmlSearchNsByNamespaceStrict: * @doc: the document * @node: the start node * @nsName: the searched namespace name * @retNs: the resulting ns-decl * @prefixed: if the found ns-decl must have a prefix (for attributes) * * Dynamically searches for a ns-declaration which matches * the given @nsName in the ancestor-or-self axis of @node. * * Returns 1 if a ns-decl was found, 0 if not and -1 on API *

Source from the content-addressed store, hash-verified

8306* and internal errors.
8307*/
8308static int
8309xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node,
8310 const xmlChar* nsName,
8311 xmlNsPtr *retNs, int prefixed)
8312{
8313 xmlNodePtr cur, prev = NULL, out = NULL;
8314 xmlNsPtr ns, prevns;
8315
8316 if ((doc == NULL) || (nsName == NULL) || (retNs == NULL))
8317 return (-1);
8318 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
8319 return(-1);
8320
8321 *retNs = NULL;
8322 if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) {
8323 *retNs = xmlTreeEnsureXMLDecl(doc);
8324 if (*retNs == NULL)
8325 return (-1);
8326 return (1);
8327 }
8328 cur = node;
8329 do {
8330 if (cur->type == XML_ELEMENT_NODE) {
8331 if (cur->nsDef != NULL) {
8332 for (ns = cur->nsDef; ns != NULL; ns = ns->next) {
8333 if (prefixed && (ns->prefix == NULL))
8334 continue;
8335 if (prev != NULL) {
8336 /*
8337 * Check the last level of ns-decls for a
8338 * shadowing prefix.
8339 */
8340 prevns = prev->nsDef;
8341 do {
8342 if ((prevns->prefix == ns->prefix) ||
8343 ((prevns->prefix != NULL) &&
8344 (ns->prefix != NULL) &&
8345 xmlStrEqual(prevns->prefix, ns->prefix))) {
8346 /*
8347 * Shadowed.
8348 */
8349 break;
8350 }
8351 prevns = prevns->next;
8352 } while (prevns != NULL);
8353 if (prevns != NULL)
8354 continue;
8355 }
8356 /*
8357 * Ns-name comparison.
8358 */
8359 if ((nsName == ns->href) ||
8360 xmlStrEqual(nsName, ns->href)) {
8361 /*
8362 * At this point the prefix can only be shadowed,
8363 * if we are the the (at least) 3rd level of
8364 * ns-decls.
8365 */

Callers 1

xmlDOMWrapAdoptAttrFunction · 0.85

Calls 3

xmlStrEqualFunction · 0.85
xmlTreeEnsureXMLDeclFunction · 0.85
xmlNsInScopeFunction · 0.85

Tested by

no test coverage detected