Question: What is the correct way to register the default NS for XPath context?
I've gone through numerous posts (mostly non-C++ and Google search) about registering NS, but I cannot find anything for the default namespace and because of that, I cannot search by XPath.
Given the following XML document, the XPath search will only work if the default namespace is not specified (which I can't omit).
<EDSCrate xmlns="http://aviation-ia.com/aeec/SupportFiles/827"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CrateData id="blah">...</CrateData>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">...</ds:Signature>
</EDSCrate>
I tried registering the default NS as "empty" before searching by XPath but it still doesn't work.
xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
xmlXPathRegisterNs(xpathCtx, (const xmlChar*) "", (const xmlChar*)"http://aviation-ia.com/aeec/SupportFiles/827");
//xmlXPathRegisterNs(xpathCtx, NULL, (const xmlChar*)"http://aviation-ia.com/aeec/SupportFiles/827");
xmlXPathRegisterNs(xpathCtx, (const xmlChar*) "xsi", (const xmlChar*)"http://www.w3.org/2001/XMLSchema-instance");
xmlXPathRegisterNs(xpathCtx, (const xmlChar*) "ds", (const xmlChar*)"http://www.w3.org/2000/09/xmldsig#");
The code works if xmlns= is removed from the root node.
Searching for the following simple XPath will return nothing, example;
/EDSCrate/EDSCrate/CrateData
I looked through the libxml2 documentation, there is a deprecated way to register global NS at the document level via xmlNewGlobalNs but that doesn't apply to XPath context...
Then looking at the xmlXPathContext definition, there seems to be a namespaces and nsHash table in it... am I supposed to brute-force register an NS in there?
Update:
Hum... looks like there is an open bug for it? https://gitlab.gnome.org/GNOME/libxml2/-/issues/585
Does anyone know a workaround?