XQuilla/docs/dom3-api/dom-context-item_8cpp-example.html

73 lines
5.3 KiB
HTML
Raw Normal View History

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&amp;type=2" border="0" alt="SourceForge.net Logo" /></a>
2020-02-17 21:19:08 +00:00
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="examples.html">Examples</a></div>
2020-02-17 21:17:06 +00:00
<h1>dom-context-item.cpp</h1>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"><pre class="fragment"><span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="DOM_8hpp.html">xercesc/dom/DOM.hpp</a>&gt;</span>
<span class="preprocessor">#include &lt;xercesc/framework/StdOutFormatTarget.hpp&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="xqilla-dom3_8hpp.html">xqilla/xqilla-dom3.hpp</a>&gt;</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:08 +00:00
<a name="a3"></a><a class="code" href="classXQillaPlatformUtils.html#e0">XQillaPlatformUtils::initialize</a>();
2020-02-17 21:17:06 +00:00
<span class="comment">// Get the XQilla DOMImplementation object</span>
DOMImplementation *xqillaImplementation =
DOMImplementationRegistry::getDOMImplementation(X(<span class="stringliteral">"XPath2 3.0"</span>));
<span class="keywordflow">try</span> {
<span class="comment">// Create a DOMLSParser object</span>
2020-02-17 21:19:08 +00:00
<a name="_a4"></a><a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMLSParser&gt;</a> parser(xqillaImplementation-&gt;createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0));
2020-02-17 21:17:06 +00:00
parser-&gt;getDomConfig()-&gt;setParameter(XMLUni::fgDOMNamespaces, <span class="keyword">true</span>);
parser-&gt;getDomConfig()-&gt;setParameter(XMLUni::fgXercesSchema, <span class="keyword">true</span>);
parser-&gt;getDomConfig()-&gt;setParameter(XMLUni::fgDOMValidateIfSchema, <span class="keyword">true</span>);
<span class="comment">// Parse a DOMDocument</span>
DOMDocument *document = parser-&gt;parseURI(<span class="stringliteral">"foo.xml"</span>);
<span class="keywordflow">if</span>(document == 0) {
std::cerr &lt;&lt; <span class="stringliteral">"Document not found."</span> &lt;&lt; std::endl;
<span class="keywordflow">return</span> 1;
}
<span class="comment">// Parse an XPath 2 expression</span>
<a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMXPathExpression&gt;</a> expression(document-&gt;createExpression(X(<span class="stringliteral">"foo/bar/@baz"</span>), 0));
<span class="comment">// Execute the query</span>
<a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMXPathResult&gt;</a> result(expression-&gt;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&lt;DOMLSSerializer&gt;</a> serializer(xqillaImplementation-&gt;createLSSerializer());
<a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMLSOutput&gt;</a> output(xqillaImplementation-&gt;createLSOutput());
StdOutFormatTarget target;
output-&gt;setByteStream(&amp;target);
<span class="comment">// Iterate over the results, printing them</span>
<span class="keywordflow">while</span>(result-&gt;iterateNext()) {
serializer-&gt;write(result-&gt;getNodeValue(), output);
std::cout &lt;&lt; std::endl;
}
}
<span class="keywordflow">catch</span>(XQillaException &amp;e) {
std::cerr &lt;&lt; <span class="stringliteral">"XQillaException: "</span> &lt;&lt; UTF8(e.getString()) &lt;&lt; std::endl;
<span class="keywordflow">return</span> 1;
}
<span class="comment">// Terminate Xerces-C and XQilla using XQillaPlatformUtils</span>
2020-02-17 21:19:08 +00:00
<a name="a5"></a><a class="code" href="classXQillaPlatformUtils.html#e1">XQillaPlatformUtils::terminate</a>();
2020-02-17 21:17:06 +00:00
<span class="keywordflow">return</span> 0;
}
2020-02-17 21:19:08 +00:00
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Fri Sep 25 06:55:48 2009 for XQilla DOM Level 3 API by&nbsp;
2020-02-17 21:17:06 +00:00
<a href="http://www.doxygen.org/index.html">
2020-02-17 21:19:08 +00:00
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
2020-02-17 21:17:06 +00:00
</body>
</html>