Search code examples
xmlxpathtinyxpath

TinyXPath: Failure to find relative descendant


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):

<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:

#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;
}

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


Solution

  • To the benefit of others in my situation, I'd like to answer to my own question.

    The issue has been a long-standing problem with TinyXPath, as discussed in this thread on the TinyXPath discussion forum.

    The issue was finally resolved by Andrey Antsut as of TinyXPath TinyXPath inofficial version 1.3.2 (this is actually the sole link to this "release" that I have found).