* xmlNodeSetBase: * @cur: the node being changed * @uri: the new base URI * * Set (or reset) the base URI of a node, i.e. the value of the * xml:base attribute. * * Returns 0 on success, -1 on error. */
| 5317 | * Returns 0 on success, -1 on error. |
| 5318 | */ |
| 5319 | int |
| 5320 | xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) { |
| 5321 | xmlNsPtr ns; |
| 5322 | xmlChar* fixed; |
| 5323 | |
| 5324 | if (cur == NULL) |
| 5325 | return(-1); |
| 5326 | switch(cur->type) { |
| 5327 | case XML_ELEMENT_NODE: |
| 5328 | case XML_ATTRIBUTE_NODE: |
| 5329 | break; |
| 5330 | case XML_DOCUMENT_NODE: |
| 5331 | case XML_HTML_DOCUMENT_NODE: { |
| 5332 | xmlDocPtr doc = (xmlDocPtr) cur; |
| 5333 | |
| 5334 | if (doc->URL != NULL) |
| 5335 | xmlFree((xmlChar *) doc->URL); |
| 5336 | if (uri == NULL) { |
| 5337 | doc->URL = NULL; |
| 5338 | } else { |
| 5339 | doc->URL = xmlPathToURI(uri); |
| 5340 | if (doc->URL == NULL) |
| 5341 | return(-1); |
| 5342 | } |
| 5343 | return(0); |
| 5344 | } |
| 5345 | default: |
| 5346 | return(-1); |
| 5347 | } |
| 5348 | |
| 5349 | xmlSearchNsByHrefSafe(cur, XML_XML_NAMESPACE, &ns); |
| 5350 | if (ns == NULL) |
| 5351 | return(-1); |
| 5352 | fixed = xmlPathToURI(uri); |
| 5353 | if (fixed == NULL) |
| 5354 | return(-1); |
| 5355 | if (xmlSetNsProp(cur, ns, BAD_CAST "base", fixed) == NULL) { |
| 5356 | xmlFree(fixed); |
| 5357 | return(-1); |
| 5358 | } |
| 5359 | xmlFree(fixed); |
| 5360 | |
| 5361 | return(0); |
| 5362 | } |
| 5363 | #endif /* LIBXML_TREE_ENABLED */ |
| 5364 | |
| 5365 | /** |
no test coverage detected