TinyXPath: Failure to find relative descendant

harrisoneagle

New Member
The small footprint of TinyXPath makes it an attractive package for simple XPath queries. However, some of its functionality seems not to work the way one (newbie) would expect it to. Specifically, I can't seem to be able to obtain matches for trivial descendants of a particular (non-root) node. This question regards a nearly identical issue, but the proposed answer does not work when the XPath expression targets a descendant beyond the nearest children.Example input (test.xml):\[code\]<A><B val="123"> <C> <D val="321">123</D> <E>e</E> </C> <F>f</F></B><C> <D val="432">d1</D></C></A>\[/code\]Code:\[code\]#include "xpath_static.h"int mainSO() { TiXmlDocument doc; if(doc.LoadFile("test.xml")) { TiXmlNode* pRoot = doc.RootElement(); assert(pRoot); const TiXmlNode* pChild(nullptr); TinyXPath::o_xpath_node(pRoot, "/A/B", pChild); // OK! Root-relative expressions work. const TiXmlNode* pChild2(nullptr); TinyXPath::o_xpath_node(pChild, "C", pChild2); // OK! const TiXmlNode* pChild3(nullptr); TinyXPath::o_xpath_node(pChild, "C/D", pChild3); // Fail! // TinyXPath::o_xpath_node(pChild, ".C/D", pChild3); // Fail! // TinyXPath::o_xpath_node(pChild, ".//C/D", pChild3); // Fail!}return 0;}\[/code\]The internal xpath_processor inside o_xpath_node reports no errors; there are simply no matches. I tried also the formulation in this answer -- it does indeed return a match, however it returns only node C, not C/D.Anyone had a similar problem? Did I misformat the XPath expressions? I had hoped the TinyXPath documentation could give some pointers but... Documentation! Is! SPARTAN!Cheers,Klas
 
Back
Top