I am supporting a legacy C++ application which uses Xerces-C for XML parsing. I've been spoiled by .Net and am used to using XPath to select nodes from a DOM tree.
Is there any way to get access some limited XPath functionality in Xerces-C? I'm looking for something like selectNodes("/for/bar/baz"). I could do this manually, but XPath is so nice by comparison.
Here is a working example of XPath evaluation with Xerces 3.1.2.
Sample XML
C++
Compile and run (assumes standard xerces library installation and C++ file named xpath.cpp)
Result
According to the FAQ, Xerces-C supports partial XPath 1 implementation:
You use DOMDocument::evaluate() to evaluate the expression, which then returns a DOMXPathResult.
See the xerces faq.
http://xerces.apache.org/xerces-c/faq-other-2.html#faq-9
Does Xerces-C++ support XPath? No.Xerces-C++ 2.8.0 and Xerces-C++ 3.0.1 only have partial XPath implementation for the purposes of handling Schema identity constraints. For full XPath support, you can refer Apache Xalan C++ or other Open Source Projects like Pathan.
It's fairly easy to do what you want using xalan however.