90 lines
6.6 KiB
HTML
90 lines
6.6 KiB
HTML
<!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>
|
|
<!-- Generated by Doxygen 1.8.5 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<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><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">dom-context-item.cpp</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<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>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include <iostream></span></div>
|
|
<div class="line"><span class="preprocessor">#include <<a class="code" href="DOM_8hpp.html">xercesc/dom/DOM.hpp</a>></span></div>
|
|
<div class="line"><span class="preprocessor">#include <xercesc/framework/StdOutFormatTarget.hpp></span></div>
|
|
<div class="line"><span class="preprocessor">#include <<a class="code" href="xqilla-dom3_8hpp.html">xqilla/xqilla-dom3.hpp</a>></span></div>
|
|
<div class="line"></div>
|
|
<div class="line">XERCES_CPP_NAMESPACE_USE;</div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) {</div>
|
|
<div class="line"> <span class="comment">// Initialise Xerces-C and XQilla using XQillaPlatformUtils</span></div>
|
|
<div class="line"> <a name="a0"></a><a class="code" href="classXQillaPlatformUtils.html#ac769d09556ec43ecb94d1822783ba0b8">XQillaPlatformUtils::initialize</a>();</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Get the XQilla DOMImplementation object</span></div>
|
|
<div class="line"> DOMImplementation *xqillaImplementation =</div>
|
|
<div class="line"> DOMImplementationRegistry::getDOMImplementation(X(<span class="stringliteral">"XPath2 3.0"</span>));</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordflow">try</span> {</div>
|
|
<div class="line"> <span class="comment">// Create a DOMLSParser object</span></div>
|
|
<div class="line"> <a name="_a1"></a><a class="code" href="classAutoRelease.html">AutoRelease<DOMLSParser></a> parser(xqillaImplementation->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0));</div>
|
|
<div class="line"> parser->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, <span class="keyword">true</span>);</div>
|
|
<div class="line"> parser->getDomConfig()->setParameter(XMLUni::fgXercesSchema, <span class="keyword">true</span>);</div>
|
|
<div class="line"> parser->getDomConfig()->setParameter(XMLUni::fgDOMValidateIfSchema, <span class="keyword">true</span>);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Parse a DOMDocument</span></div>
|
|
<div class="line"> DOMDocument *document = parser->parseURI(<span class="stringliteral">"foo.xml"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">if</span>(document == 0) {</div>
|
|
<div class="line"> std::cerr << <span class="stringliteral">"Document not found."</span> << std::endl;</div>
|
|
<div class="line"> <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Parse an XPath 2 expression</span></div>
|
|
<div class="line"> <a class="code" href="classAutoRelease.html">AutoRelease<DOMXPathExpression></a> expression(document->createExpression(X(<span class="stringliteral">"foo/bar/@baz"</span>), 0));</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Execute the query</span></div>
|
|
<div class="line"> <a class="code" href="classAutoRelease.html">AutoRelease<DOMXPathResult></a> result(expression->evaluate(document, DOMXPathResult::ITERATOR_RESULT_TYPE, 0));</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Create a DOMLSSerializer to output the nodes</span></div>
|
|
<div class="line"> <a class="code" href="classAutoRelease.html">AutoRelease<DOMLSSerializer></a> serializer(xqillaImplementation->createLSSerializer());</div>
|
|
<div class="line"> <a class="code" href="classAutoRelease.html">AutoRelease<DOMLSOutput></a> output(xqillaImplementation->createLSOutput());</div>
|
|
<div class="line"> StdOutFormatTarget target;</div>
|
|
<div class="line"> output->setByteStream(&target);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Iterate over the results, printing them</span></div>
|
|
<div class="line"> <span class="keywordflow">while</span>(result->iterateNext()) {</div>
|
|
<div class="line"> serializer->write(result->getNodeValue(), output);</div>
|
|
<div class="line"> std::cout << std::endl;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> <span class="keywordflow">catch</span>(XQillaException &e) {</div>
|
|
<div class="line"> std::cerr << <span class="stringliteral">"XQillaException: "</span> << UTF8(e.getString()) << std::endl;</div>
|
|
<div class="line"> <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Terminate Xerces-C and XQilla using XQillaPlatformUtils</span></div>
|
|
<div class="line"> <a name="a2"></a><a class="code" href="classXQillaPlatformUtils.html#a0bd04a35d4cb26894497c6ff4d8e2105">XQillaPlatformUtils::terminate</a>();</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line">}</div>
|
|
</div><!-- fragment --> </div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.5
|
|
</small></address>
|
|
</body>
|
|
</html>
|