यहां Xerces 3.1.2 के साथ XPath मूल्यांकन का एक कामकाजी उदाहरण है।
नमूना XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<ApplicationSettings>hello world</ApplicationSettings>
</root>
सी ++
#include <iostream>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/util/TransService.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
using namespace xercesc;
using namespace std;
int main()
{
XMLPlatformUtils::Initialize();
// create the DOM parser
XercesDOMParser *parser = new XercesDOMParser;
parser->setValidationScheme(XercesDOMParser::Val_Never);
parser->parse("sample.xml");
// get the DOM representation
DOMDocument *doc = parser->getDocument();
// get the root element
DOMElement* root = doc->getDocumentElement();
// evaluate the xpath
DOMXPathResult* result=doc->evaluate(
XMLString::transcode("/root/ApplicationSettings"),
root,
NULL,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL);
if (result->getNodeValue() == NULL)
{
cout << "There is no result for the provided XPath " << endl;
}
else
{
cout<<TranscodeToStr(result->getNodeValue()->getFirstChild()->getNodeValue(),"ascii").str()<<endl;
}
XMLPlatformUtils::Terminate();
return 0;
}
संकलित करें और चलाने के
(मानक xerces पुस्तकालय स्थापना और सी ++ फ़ाइल का नाम
xpath.cpp मान लिया गया है)
परिणाम
hello world
स्रोत
2015-10-14 18:20:47
किसी को भी इस कार्यक्षमता का उपयोग किया गया है? क्या यह काम करता है? यदि हां, तो Xerces-C के किस संस्करण के लिए? –
@AdamTegen हाँ, मुझे पता है कि यह 6 साल बाद है लेकिन जेरिस अभी भी लोकप्रिय है। मैंने Xerces 3.1.2 के साथ XPath मूल्यांकन को पूरा करने का एक उदाहरण प्रदान किया। –