I'm not sure if you are using DOM - but if you are, I recently wrote a small example/test that includes pre-compile XPaths. This depends heavily on XQilla - which I am sure most XercesC developers/users recommend if you are planning on using XPaths. I am using the XQilla "SimpleAPI" - which allows for more optimal approaches to applications that heavily depend upon XPaths.
Anyway, I include the code - hoping it may help you with this sort of stuff. #include <iostream> #include <fstream> #include <xqilla/xqilla-dom3.hpp> #include <xqilla/xqilla-simple.hpp> #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/XercesDefs.hpp> #include <xercesc/dom/DOM.hpp> /* File foo.xml is as follows. <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <!DOCTYPE div><div xmlns="http://www.w3.org/1999/xhtml"> <h5>Foo</h5><div><span class="phoo">wibble</span></div> </div> File bar.xml is as follows. <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE div><div xmlns="http://www.w3.org/1999/xhtml"> <h5>Bar</h5><div><span class="bah">wobble</span></div> </div> */ using namespace xercesc; using namespace std; class errhandler : public DOMErrorHandler { public: bool handleError(const DOMError& domError) { cout << UTF8(domError.getMessage()); return true; } }; errhandler* err = NULL; //dom DOMImplementation* impl = NULL; DOMLSParser* parser = NULL; DOMDocument* d1 = NULL; DOMDocument* d2 = NULL; //xqilla DynamicContext* central = NULL; XQilla* xqilla = NULL; XercesConfiguration* xc = NULL; XQQuery* q1 = NULL; XQQuery* q2 = NULL; DOMDocument* DOMDocFromFile(const XMLCh* const uri) { DOMDocument* rslt = NULL; try { rslt = parser->parseURI(uri); } catch (...) { std::cout << "DOM Parse error" << std::endl; } return rslt; } void doDocQuery(DOMDocument* d,XQQuery* q) { DOMElement* el = d->getDocumentElement(); if (el != NULL) { AutoDelete<DynamicContext> c(q->createDynamicContext()); c->setContextItem(((XercesConfiguration*)c->getConfiguration())->createNode(el,c)); Result result = q->execute(c); Item::Ptr item; while((item = result->next(c))) { std::cout << UTF8(item->asString(c)) << ";"; } } } int main(int argc, char *argv[]) { err = new errhandler(); XQillaPlatformUtils::initialize(); xqilla = new XQilla(); xc = new XercesConfiguration(); impl = DOMImplementationRegistry::getDOMImplementation(X("XPath2 3.0")); parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS,NULL); DOMConfiguration* dc = parser->getDomConfig(); dc->setParameter(XMLUni::fgDOMErrorHandler,err); dc->setParameter(XMLUni::fgXercesUserAdoptsDOMDocument,true); central = xqilla->createContext(XQilla::XPATH3,xc); central->setNamespaceBinding(X("h"),X("http://www.w3.org/1999/xhtml")); q1 = xqilla->parse(X("//h:span[@class]/@class"),central,NULL,0x12); q2 = xqilla->parse(X("//h:h5/text()"),central,NULL,0x12); //initialise process is done for (int i = 1; i <= 100; i++) { cout << "iteration " << i << ":"; d1 = DOMDocFromFile(X("foo.xml")); d2 = DOMDocFromFile(X("bar.xml")); doDocQuery(d1,q1); doDocQuery(d1,q2); doDocQuery(d2,q1); doDocQuery(d2,q2); d1->release(); d2->release(); cout << endl; } //now teardown variables delete q1; delete q2; delete central; parser->release(); delete xc; delete xqilla; delete err; return 0; }
smime.p7s
Description: S/MIME cryptographic signature
