* xmlXPathRegisterNs: * @ctxt: the XPath context * @prefix: the namespace prefix cannot be NULL or empty string * @ns_uri: the namespace name * * Register a new namespace. If @ns_uri is NULL it unregisters * the namespace * * Returns 0 in case of success, -1 in case of error */
| 4205 | * Returns 0 in case of success, -1 in case of error |
| 4206 | */ |
| 4207 | int |
| 4208 | xmlXPathRegisterNs(xmlXPathContextPtr ctxt, const xmlChar *prefix, |
| 4209 | const xmlChar *ns_uri) { |
| 4210 | xmlChar *copy; |
| 4211 | |
| 4212 | if (ctxt == NULL) |
| 4213 | return(-1); |
| 4214 | if (prefix == NULL) |
| 4215 | return(-1); |
| 4216 | if (prefix[0] == 0) |
| 4217 | return(-1); |
| 4218 | |
| 4219 | if (ctxt->nsHash == NULL) |
| 4220 | ctxt->nsHash = xmlHashCreate(10); |
| 4221 | if (ctxt->nsHash == NULL) { |
| 4222 | xmlXPathErrMemory(ctxt); |
| 4223 | return(-1); |
| 4224 | } |
| 4225 | if (ns_uri == NULL) |
| 4226 | return(xmlHashRemoveEntry(ctxt->nsHash, prefix, |
| 4227 | xmlHashDefaultDeallocator)); |
| 4228 | |
| 4229 | copy = xmlStrdup(ns_uri); |
| 4230 | if (copy == NULL) { |
| 4231 | xmlXPathErrMemory(ctxt); |
| 4232 | return(-1); |
| 4233 | } |
| 4234 | if (xmlHashUpdateEntry(ctxt->nsHash, prefix, copy, |
| 4235 | xmlHashDefaultDeallocator) < 0) { |
| 4236 | xmlXPathErrMemory(ctxt); |
| 4237 | xmlFree(copy); |
| 4238 | return(-1); |
| 4239 | } |
| 4240 | |
| 4241 | return(0); |
| 4242 | } |
| 4243 | |
| 4244 | /** |
| 4245 | * xmlXPathNsLookup: |