Issue using "//" in xpath expression

  • user_411

    user_411 - 2007-06-19

    Hi all,

    I'm new to TinyXPath, but I've used TinyXML in a few projects. I'm getting a runtime exception or just inaccurate results when using // in xpath query strings; perhaps someone can tell me what's going wrong.

    The setup:
    Using Visual Studio 2005

    TiXmlDocument doc;    // XML document
    TiXmlElement * root;    // root node of doc
    TinyXPath::xpath_processor * nodes;

    /* Loaded the following into doc
        <Test attr="yep">
            <ITest attr2="yep">
                <Test node="sure"/>

    root = config.RootElement();
    nodes = new TinyXPath::xpath_processor( root, "/TestMap//Test" );

    unsigned int nodeCount =  nodes->u_compute_xpath_node_set();
    printf("XPath found %u nodes\n" , nodeCount);

    Only 2 nodes get found with this query, but I was expecting 4.

    Even worse, if I do a

    nodes = new TinyXPath::xpath_processor( root, "//Test" );

    I get a runtime error with TiXmlAttributeSet::First() being the next statement to be executed.

    Am I not submitting a proper node for searching? Any help would be much appreciated!

    • Yves Berquin

      Yves Berquin - 2007-06-20

      I'm not able to reproduce your 2nd problem: it works fine with me, and returns 4 as expected.

      I can reproduce your first problem: the return value of 2 is wrong and should be 4.


    • user_411

      user_411 - 2007-06-21

      Thanks for the quick response Yves.

      I set up a standalone project and cannot reproduce the second issue I describe there either.

      After taking the vanilla version and inserting it into the larger project I get the issue with "//" in XPath queries causing a runtime error no matter where the code is inserted.

      The debugger shows notable differences between the nodes * xpath_processor in the two instances. Running standalone, the o, i, and d _content seem to be properly set to false, 0, and 0.0. Running with other code they have values.

      Both instances show a e_error of -842150451 that doesn't evaluate as equal to any of the e_error types. Running standalone, er_result.e_type is e_invalid, while it's -842150451 with other code present.

      Does it seem like the state above could indicate some memory issues? I'm thinking something could going wrong elsewhere that's causing corruption. When I change the TiXmlDocument, TiXmlElement*, and TinyXPath::xpath_processor in the test class to static, the debugger appears to properly set the er_result o, i, and d content values, but still throws the "access violation reading location xxx" errors and points the next instruction to TiXmlAttributeSet::First().

      Any thoughts on the matter are appreciated. I'm interested in what you think could be the core of the problem.

    • user_411

      user_411 - 2007-06-21


      I replaced the tinyxml files included with tinyxpath with the newest version (2.5.3), which happens to be what I was using with the rest of the project and rebuilt the libraries. The xpath call that used to hang the program runs just fine now.

      Whew...should have tried that a while ago. Thanks again for the help!


Log in to post a comment.