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:
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.
Thanks!
Andy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
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:
[code]
TiXmlDocument xmlDocument("test.xml");
xmlDocument.LoadFile();
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();
[/code]
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.
Thanks!
Andy
Andy,
Right now there's no other way, but it can easily be grouped together in a global function.
Yves
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!