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

Function xmlSearchNsByHrefSafe

ThirdParty/libxml2/vtklibxml2/tree.c:6197–6276  ·  view source on GitHub ↗

* xmlSearchNsByHrefSafe: * @node: a node * @href: a namespace URI * @out: pointer to resulting namespace * * Search a namespace matching @URI in scope of @node. * * Returns 0 on success, -1 if a memory allocation failed, 1 on * other errors. */

Source from the content-addressed store, hash-verified

6195 * other errors.
6196 */
6197int
6198xmlSearchNsByHrefSafe(xmlNodePtr node, const xmlChar *href,
6199 xmlNsPtr *out) {
6200 xmlNsPtr cur;
6201 xmlDocPtr doc;
6202 xmlNodePtr orig = node;
6203 xmlNodePtr parent;
6204 int is_attr;
6205
6206 if (out == NULL)
6207 return(1);
6208 *out = NULL;
6209 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
6210 return(1);
6211
6212 doc = node->doc;
6213
6214 if ((doc != NULL) && (xmlStrEqual(href, XML_XML_NAMESPACE))) {
6215 cur = xmlTreeEnsureXMLDecl(doc);
6216 if (cur == NULL)
6217 return(-1);
6218 *out = cur;
6219 return(0);
6220 }
6221
6222 is_attr = (node->type == XML_ATTRIBUTE_NODE);
6223
6224 while (node->type != XML_ELEMENT_NODE) {
6225 node = node->parent;
6226 if (node == NULL)
6227 return(0);
6228 }
6229
6230 parent = node;
6231
6232 while ((node != NULL) && (node->type == XML_ELEMENT_NODE)) {
6233 cur = node->nsDef;
6234 while (cur != NULL) {
6235 if (xmlStrEqual(cur->href, href)) {
6236 if (((!is_attr) || (cur->prefix != NULL)) &&
6237 (xmlNsInScope(doc, orig, node, cur->prefix) == 1)) {
6238 *out = cur;
6239 return(0);
6240 }
6241 }
6242 cur = cur->next;
6243 }
6244 if (orig != node) {
6245 cur = node->ns;
6246 if (cur != NULL) {
6247 if (xmlStrEqual(cur->href, href)) {
6248 if (((!is_attr) || (cur->prefix != NULL)) &&
6249 (xmlNsInScope(doc, orig, node,
6250 cur->prefix) == 1)) {
6251 *out = cur;
6252 return(0);
6253 }
6254 }

Callers 5

xmlNodeSetLangFunction · 0.85
xmlNodeSetSpacePreserveFunction · 0.85
xmlNodeSetBaseFunction · 0.85
xmlSearchNsByHrefFunction · 0.85
xmlNewReconciledNsFunction · 0.85

Calls 4

xmlStrEqualFunction · 0.85
xmlTreeEnsureXMLDeclFunction · 0.85
xmlNsInScopeFunction · 0.85
xmlNewXmlNsFunction · 0.85

Tested by

no test coverage detected