XQuilla/docs/simple-api/simple-context-item_8cpp-example.html

68 lines
4.7 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 Simple 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:24:47 +00:00
<!-- Generated by Doxygen 1.8.5 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;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>
2020-02-17 21:24:47 +00:00
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">simple-context-item.cpp</div> </div>
</div><!--header-->
2020-02-17 21:19:57 +00:00
<div class="contents">
2020-02-17 21:24:47 +00:00
<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 &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="xqilla-simple_8hpp.html">xqilla/xqilla-simple.hpp</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="Sequence_8hpp.html">xqilla/runtime/Sequence.hpp</a>&gt;</span></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 by creating the factory object</span></div>
<div class="line"> <a name="_a0"></a><a class="code" href="classXQilla.html">XQilla</a> xqilla;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Parse an XQuery expression</span></div>
<div class="line"> <span class="comment">// (AutoDelete deletes the object at the end of the scope)</span></div>
<div class="line"> <a name="_a1"></a><a class="code" href="classAutoDelete.html">AutoDelete&lt;XQQuery&gt;</a> query(xqilla.<a name="a2"></a><a class="code" href="classXQilla.html#a7475d47b7b2fc51434ba9a381431f7ec">parse</a>(X(<span class="stringliteral">&quot;foo/bar/@baz&quot;</span>)));</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Create a context object</span></div>
<div class="line"> <a class="code" href="classAutoDelete.html">AutoDelete&lt;DynamicContext&gt;</a> context(query-&gt;createDynamicContext());</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Parse a document, and set it as the context item</span></div>
<div class="line"> <a name="_a3"></a><a class="code" href="classSequence.html">Sequence</a> seq = context-&gt;resolveDocument(X(<span class="stringliteral">&quot;foo.xml&quot;</span>));</div>
<div class="line"> <span class="keywordflow">if</span>(!seq.isEmpty() &amp;&amp; seq.first()-&gt;isNode()) {</div>
<div class="line"> context-&gt;setContextItem(seq.first());</div>
<div class="line"> context-&gt;setContextPosition(1);</div>
<div class="line"> context-&gt;setContextSize(1);</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Execute the query, using the context</span></div>
<div class="line"> <a name="_a4"></a><a class="code" href="classResult.html">Result</a> result = query-&gt;execute(context);</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Iterate over the results, printing them</span></div>
<div class="line"> <a name="_a5"></a><a class="code" href="classRefCountPointer.html">Item::Ptr</a> item;</div>
<div class="line"> <span class="keywordflow">while</span>(item = result-&gt;<a name="a6"></a><a class="code" href="classResultImpl.html#a4820c3c36a27975b1b704b903d2d1c5f">next</a>(context)) {</div>
<div class="line"> std::cout &lt;&lt; UTF8(item-&gt;<a name="a7"></a><a class="code" href="classItem.html#aeefef8ff091f935f4c81b53031582561">asString</a>(context)) &lt;&lt; std::endl;</div>
<div class="line"> }</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 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.5
</small></address>
2020-02-17 21:17:06 +00:00
</body>
</html>