I'm using Xercesc-3-1, and I'm trying to resolve an XPath. The code looks like:
auto result = documents[ref.refDoc]->evaluate(XMLString::transcode(ref.oldXPath.c_str()),
documents[ref.refDoc],
documents[ref.refDoc]->createNSResolver(documents[ref.refDoc]->getFirstChild()),
DOMXPathResult::STRING_TYPE,
nullptr);
The first child of the document root contents the xmls:example definition. I don't see the problem, but I get a DOMException:
Exception message:attempt is made to create or change an object in a way which is incorrect with respect to namespaces
All the Links I found on Stackoverflow don't help me. So, can someone directly help me?
I figured out what the problem is and would like to answer the question here. Maybe somebody else has the same problem...
The code is correct. The problem is created by parsing the xml file. The parser which created the DOMDocument doesn't resolve the namespaces correctly, because the setDoNamesspace(...) is set by default to false. So there are no namespaces set in the dom tree and that caused the error. The problem here is, if you just print the dom tree it will be shown with the correct namespace und names.