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

49 lines
3.9 KiB
HTML
Raw Normal View History

2020-02-17 22:17:06 +01: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 22:19:08 +01: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 22:17:06 +01:00
<h1>simple-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="xqilla-simple_8hpp.html">xqilla/xqilla-simple.hpp</a>&gt;</span>
<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 by creating the factory object</span>
2020-02-17 22:19:08 +01:00
<a name="_a5"></a><a class="code" href="classXQilla.html">XQilla</a> xqilla;
2020-02-17 22:17:06 +01:00
<span class="comment">// Parse an XQuery expression</span>
<span class="comment">// (AutoDelete deletes the object at the end of the scope)</span>
2020-02-17 22:19:08 +01:00
<a name="_a6"></a><a class="code" href="classAutoDelete.html">AutoDelete&lt;XQQuery&gt;</a> query(xqilla.<a name="a7"></a><a class="code" href="classXQilla.html#z1_0">parse</a>(X(<span class="stringliteral">"foo/bar/@baz"</span>)));
2020-02-17 22:17:06 +01:00
<span class="comment">// Create a context object</span>
<a class="code" href="classAutoDelete.html">AutoDelete&lt;DynamicContext&gt;</a> context(query-&gt;createDynamicContext());
<span class="comment">// Parse a document, and set it as the context item</span>
2020-02-17 22:19:08 +01:00
<a name="_a8"></a><a class="code" href="classSequence.html">Sequence</a> seq = context-&gt;resolveDocument(X(<span class="stringliteral">"foo.xml"</span>));
<span class="keywordflow">if</span>(!seq.<a name="a9"></a><a class="code" href="classSequence.html#a24">isEmpty</a>() &amp;&amp; seq.<a name="a10"></a><a class="code" href="classSequence.html#a8">first</a>()-&gt;isNode()) {
context-&gt;setContextItem(seq.<a class="code" href="classSequence.html#a8">first</a>());
2020-02-17 22:17:06 +01:00
context-&gt;setContextPosition(1);
context-&gt;setContextSize(1);
}
<span class="comment">// Execute the query, using the context</span>
2020-02-17 22:19:08 +01:00
<a name="_a11"></a><a class="code" href="classResult.html">Result</a> result = query-&gt;execute(context);
2020-02-17 22:17:06 +01:00
<span class="comment">// Iterate over the results, printing them</span>
2020-02-17 22:19:08 +01:00
<a name="_a12"></a><a class="code" href="classRefCountPointer.html">Item::Ptr</a> item;
2020-02-17 22:17:06 +01:00
<span class="keywordflow">while</span>(item = result-&gt;next(context)) {
std::cout &lt;&lt; UTF8(item-&gt;asString(context)) &lt;&lt; std::endl;
}
<span class="keywordflow">return</span> 0;
}
2020-02-17 22:19:08 +01:00
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Fri Sep 25 06:55:26 2009 for XQilla Simple API by&nbsp;
2020-02-17 22:17:06 +01:00
<a href="http://www.doxygen.org/index.html">
2020-02-17 22:19:08 +01:00
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
2020-02-17 22:17:06 +01:00
</body>
</html>