Given the xml file
<a>
<b>
<d>v</d>
</b>
<c>
<d>v</d>
</c>
</a>
And the xpath "//d/text()"
I want to apply the xpath only to c and not to the whole document.
This has to work with libxml2 2.7.6
Doing this does not work;
xmlNodePtr node = <node pointer to c>
xmlXPathContextPtr xpathCtx = xmlXPathNewContext( node->doc );
xpathCtx->node = node;
xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression ( "//d/text()", xpathCtx);
Returned xpathObj contains refences to both /a/b/d and /a/c/d. Only /a/c/d was expected.
Use the path .//d or .//d/text() if you want to find descendants relative to another node. A path starting with //d searches all d descendant elements of the root node (also called document node).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With