Processing multiple XPath expressions

  • Andy

    Andy - 2004-08-30


    I'm not sure if anybody is monitoring this forum, but I thought I would ask a question.

    I am a newbie with TinyXPath -- I'm using it in a small project, and I have a section of code where I load a single XML file, and then need to process several XPath expressions against the same document.  For example:


    TiXmlDocument xmlDocument("test.xml");

    TinyXPath::xpath_processor xpathProc1(xmlDocument.RootElement(), "/test/node1/@value");
    TIXML_STRING node1Value = xpathProc1.S_compute_xpath();

    TinyXPath::xpath_processor xpathProc2(xmlDocument.RootElement(), "/test/node2/@value");
    TIXML_STRING node2Value = xpathProc2.S_compute_xpath();

    TinyXPath::xpath_processor xpathProc3(xmlDocument.RootElement(), "/test/node3/@value");
    TIXML_STRING node3Value = xpathProc3.S_compute_xpath();


    Is there a way to re-use an xpath_processor object, and just pass a new XPath expression in each time, rather than creating a new xpath_processor for each?  The method I use above works, but it seems cumbersome.


    • Yves Berquin

      Yves Berquin - 2004-08-30

      Right now there's no other way, but it can easily be grouped together in a global function.

    • Andy

      Andy - 2004-09-02

      Thanks for your help.  I've been shortening to the following, to avoid wearing out my keyboard.  ;-)  A wrapper class is a good idea.

      TIXML_STRING fooValue = TinyXPath::xpath_processor(xmlDocument.RootElement(), "/test/foorbar/@value");

      Thanks again!


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks