File: simple-context-item_8cpp-example.html

package info (click to toggle)
xqilla 2.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 44,220 kB
  • ctags: 27,890
  • sloc: cpp: 72,812; ansic: 21,322; sh: 10,157; yacc: 4,806; xml: 4,327; makefile: 1,071; lex: 800; sed: 17
file content (61 lines) | stat: -rw-r--r-- 4,027 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!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>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;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>
<div class="contents">
<h1>simple-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>
<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="preprocessor">#include &lt;<a class="code" href="Sequence_8hpp.html">xqilla/runtime/Sequence.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>
  <a name="_a0"></a><a class="code" href="classXQilla.html" title="Provides factory methods for creating XQQuery and DynamicContext objects.">XQilla</a> xqilla;

  <span class="comment">// Parse an XQuery expression</span>
  <span class="comment">// (AutoDelete deletes the object at the end of the scope)</span>
  <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" title="Parse the expression contained in the given query string.">parse</a>(X(<span class="stringliteral">&quot;foo/bar/@baz&quot;</span>)));

  <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>
  <a name="_a3"></a><a class="code" href="classSequence.html" title="An eagerly evaluated result of a query execution.">Sequence</a> seq = context-&gt;resolveDocument(X(<span class="stringliteral">&quot;foo.xml&quot;</span>));
  <span class="keywordflow">if</span>(!seq.isEmpty() &amp;&amp; seq.first()-&gt;isNode()) {
    context-&gt;setContextItem(seq.first());
    context-&gt;setContextPosition(1);
    context-&gt;setContextSize(1);
  }

  <span class="comment">// Execute the query, using the context</span>
  <a name="_a4"></a><a class="code" href="classResult.html" title="A scoped pointer wrapper for the lazily evaluated query result.">Result</a> result = query-&gt;execute(context);

  <span class="comment">// Iterate over the results, printing them</span>
  <a name="_a5"></a><a class="code" href="classRefCountPointer.html">Item::Ptr</a> item;
  <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;
}
</pre></div> </div>
<hr size="1"/><address style="text-align: right;"><small>Generated on 18 May 2015 for XQilla Simple API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>