2020-02-17 21:17:06 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
< html > < head > < meta http-equiv = "Content-Type" content = "text/html;charset=iso-8859-1" >
< title > XQilla DOM3 API Documentation< / title >
< link href = "doxygen.css" rel = "stylesheet" type = "text/css" >
< link href = "tabs.css" rel = "stylesheet" type = "text/css" >
< / head > < body >
< a style = "float:right;" href = "http://sourceforge.net/projects/xqilla" > < img src = "http://sflogo.sourceforge.net/sflogo.php?group_id=152021&type=2" border = "0" alt = "SourceForge.net Logo" / > < / a >
2020-02-17 21:23:16 +00:00
<!-- Generated by Doxygen 1.6.1 -->
< div class = "navigation" id = "top" >
< div class = "tabs" >
< ul >
< li > < a href = "index.html" > < span > Main Page< / span > < / a > < / li >
2020-02-17 21:19:57 +00:00
< li > < a href = "namespaces.html" > < span > Namespaces< / span > < / a > < / li >
< li > < a href = "annotated.html" > < span > Classes< / span > < / a > < / li >
< li > < a href = "files.html" > < span > Files< / span > < / a > < / li >
< li > < a href = "examples.html" > < span > Examples< / span > < / a > < / li >
< / ul >
< / div >
< / div >
< div class = "contents" >
2020-02-17 21:23:16 +00:00
< h1 > dom-context-item.cpp< / h1 > < p > 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.< / p >
2020-02-17 21:17:06 +00:00
< div class = "fragment" > < pre class = "fragment" > < span class = "preprocessor" > #include < iostream> < / span >
< span class = "preprocessor" > #include < < a class = "code" href = "DOM_8hpp.html" > xercesc/dom/DOM.hpp< / a > > < / span >
< span class = "preprocessor" > #include < xercesc/framework/StdOutFormatTarget.hpp> < / span >
< span class = "preprocessor" > #include < < a class = "code" href = "xqilla-dom3_8hpp.html" > xqilla/xqilla-dom3.hpp< / a > > < / span >
XERCES_CPP_NAMESPACE_USE;
< span class = "keywordtype" > int< / span > main(< span class = "keywordtype" > int< / span > argc, < span class = "keywordtype" > char< / span > *argv[]) {
< span class = "comment" > // Initialise Xerces-C and XQilla using XQillaPlatformUtils< / span >
2020-02-17 21:19:57 +00:00
< a name = "a0" > < / a > < a class = "code" href = "classXQillaPlatformUtils.html#ac769d09556ec43ecb94d1822783ba0b8" title = "Perform XQilla initialization." > XQillaPlatformUtils::initialize< / a > ();
2020-02-17 21:17:06 +00:00
< span class = "comment" > // Get the XQilla DOMImplementation object< / span >
DOMImplementation *xqillaImplementation =
2020-02-17 21:19:57 +00:00
DOMImplementationRegistry::getDOMImplementation(X(< span class = "stringliteral" > " XPath2 3.0" < / span > ));
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > try< / span > {
< span class = "comment" > // Create a DOMLSParser object< / span >
2020-02-17 21:19:57 +00:00
< a name = "_a1" > < / a > < a class = "code" href = "classAutoRelease.html" > AutoRelease< DOMLSParser> < / a > parser(xqillaImplementation-> createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0));
2020-02-17 21:17:06 +00:00
parser-> getDomConfig()-> setParameter(XMLUni::fgDOMNamespaces, < span class = "keyword" > true< / span > );
parser-> getDomConfig()-> setParameter(XMLUni::fgXercesSchema, < span class = "keyword" > true< / span > );
parser-> getDomConfig()-> setParameter(XMLUni::fgDOMValidateIfSchema, < span class = "keyword" > true< / span > );
< span class = "comment" > // Parse a DOMDocument< / span >
2020-02-17 21:19:57 +00:00
DOMDocument *document = parser-> parseURI(< span class = "stringliteral" > " foo.xml" < / span > );
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > if< / span > (document == 0) {
2020-02-17 21:19:57 +00:00
std::cerr < < < span class = "stringliteral" > " Document not found." < / span > < < std::endl;
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > return< / span > 1;
}
< span class = "comment" > // Parse an XPath 2 expression< / span >
2020-02-17 21:19:57 +00:00
< a class = "code" href = "classAutoRelease.html" > AutoRelease< DOMXPathExpression> < / a > expression(document-> createExpression(X(< span class = "stringliteral" > " foo/bar/@baz" < / span > ), 0));
2020-02-17 21:17:06 +00:00
< span class = "comment" > // Execute the query< / span >
< a class = "code" href = "classAutoRelease.html" > AutoRelease< DOMXPathResult> < / a > result(expression-> evaluate(document, DOMXPathResult::ITERATOR_RESULT_TYPE, 0));
< span class = "comment" > // Create a DOMLSSerializer to output the nodes< / span >
< a class = "code" href = "classAutoRelease.html" > AutoRelease< DOMLSSerializer> < / a > serializer(xqillaImplementation-> createLSSerializer());
< a class = "code" href = "classAutoRelease.html" > AutoRelease< DOMLSOutput> < / a > output(xqillaImplementation-> createLSOutput());
StdOutFormatTarget target;
output-> setByteStream(& target);
< span class = "comment" > // Iterate over the results, printing them< / span >
< span class = "keywordflow" > while< / span > (result-> iterateNext()) {
serializer-> write(result-> getNodeValue(), output);
std::cout < < std::endl;
}
}
< span class = "keywordflow" > catch< / span > (XQillaException & e) {
2020-02-17 21:19:57 +00:00
std::cerr < < < span class = "stringliteral" > " XQillaException: " < / span > < < UTF8(e.getString()) < < std::endl;
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > return< / span > 1;
}
< span class = "comment" > // Terminate Xerces-C and XQilla using XQillaPlatformUtils< / span >
2020-02-17 21:19:57 +00:00
< a name = "a2" > < / a > < a class = "code" href = "classXQillaPlatformUtils.html#a0bd04a35d4cb26894497c6ff4d8e2105" title = "Perform XQilla termination." > XQillaPlatformUtils::terminate< / a > ();
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > return< / span > 0;
}
2020-02-17 21:19:57 +00:00
< / pre > < / div > < / div >
2020-02-17 21:23:50 +00:00
< hr size = "1" / > < address style = "text-align: right;" > < small > Generated on 8 Jul 2015 for XQilla DOM Level 3 API by
2020-02-17 21:17:06 +00:00
< a href = "http://www.doxygen.org/index.html" >
2020-02-17 21:23:16 +00:00
< img class = "footer" src = "doxygen.png" alt = "doxygen" / > < / a > 1.6.1 < / small > < / address >
2020-02-17 21:17:06 +00:00
< / body >
< / html >