This example parses a document and sets it as the context item. It then executes an XQuery expression that navigates relative to the context item.
#include <iostream>
#include <xercesc/framework/StdOutFormatTarget.hpp>
XERCES_CPP_NAMESPACE_USE;
int main(int argc, char *argv[]) {
DOMImplementation *xqillaImplementation =
DOMImplementationRegistry::getDOMImplementation(X("XPath2 3.0"));
try {
parser->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, true);
parser->getDomConfig()->setParameter(XMLUni::fgXercesSchema, true);
parser->getDomConfig()->setParameter(XMLUni::fgDOMValidateIfSchema, true);
DOMDocument *document = parser->parseURI("foo.xml");
if(document == 0) {
std::cerr << "Document not found." << std::endl;
return 1;
}
StdOutFormatTarget target;
output->setByteStream(&target);
while(result->iterateNext()) {
serializer->write(result->getNodeValue(), output);
std::cout << std::endl;
}
}
catch(XQillaException &e) {
std::cerr << "XQillaException: " << UTF8(e.getString()) << std::endl;
return 1;
}
return 0;
}