On 31/01/11 11:42, Alberto Massari wrote:
Hi Mateusz,
the DOMPrint example specifies the root element as the context node, not
the document node; so the correct behavior is for "bookstore" to return
an empty set, and "." to return the root element.
Alberto,
Your explanation makes sense, however I'm not sure if I get it how to
solve on the code level. I used DOMPrint as an example, but trying to
solve the same issue in my own application. Shortly, the issue is the
XPath expression do not select anything (not only at root level)
unless I use full absolute path anchored at root.
So, code (based on DOMPrint) discussed in my previous post boils
down to the following code - root element as the context node:
XercesDOMParser* parser = ...'
DOMDocument* doc = parser->getDocument();
DOMElement* root = doc->getDocumentElement(); // root is context node
DOMXPathNSResolver* resolver = doc->createNSResolver(root);
DOMXPathResult* result =
doc->evaluate(xpathStr, root, resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL);
Now, how to make the document a context node?
Simple replacement of root with doc is not working, obviously:
DOMXPathResult* result =
doc->evaluate(xpathStr, doc, resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL)
Do I need to configure resolver to achieve equivalent of?
DOMXPathNSResolver* resolver = doc->createNSResolver(doc);
I must admit the Xerces C++ documentation (not API reference) regarding
XPath is not very helpful here, so I'd be thankful for any piece of advice.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org