XPath 1.0 defines the attribute axis and @ as a shortcut to use it, seehttp://
www.w3.org/TR/xpath/#path-abbrev
Does Xerces implement XPath?
Yes, it does. I was provided the code below by one of Xerces' authors,
Alberto Massari.
-Ramon
---------------------
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <iostream>
using namespace std;
main(int argc, char *argv[])
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char *pMessage = XMLString::transcode(toCatch.getMessage());
fprintf(stderr, "Error during initialization! \n %s \n",
pMessage);
XMLString::release(&pMessage);
return -1;
}
XercesDOMParser parser;
parser.parse("simple-sample.xml");
DOMDocument *document = parser.getDocument();
XMLCh xpathStr[100];
XMLString::transcode("/line-segments/horizontal/distance",
xpathStr, sizeof(xpathStr) - 1);
DOMXPathResult* result = (DOMXPathResult*)document->evaluate
(xpathStr,
(const xercesc_3_1:
OMNode*)document->getDocumentElement(),
NULL,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL);
int count = result->getSnapshotLength();
for (int i = 0; i < count; i++) {
result->snapshotItem(i); // this selects the node for the
getNodeValue call
DOMNode* item = result->getNodeValue();
cout << "item #" << i+1 << ": `" << XMLString::transcode(item-
getTextContent()) << "'" << endl;
// do something with the item->getTextContent()
}
result->release();
return 0;
}