72 lines
5.2 KiB
HTML
72 lines
5.2 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 XQC 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.3.9.1 -->
|
|
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="examples.html">Examples</a></div>
|
|
<h1>xqc-context-item.c</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 <<a class="code" href="xqilla-xqc_8h.html">xqilla/xqilla-xqc.h</a>></span>
|
|
|
|
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
|
|
{
|
|
<a name="_a11"></a><a class="code" href="structXQC__Implementation__s.html">XQC_Implementation</a> *impl;
|
|
<a name="_a12"></a><a class="code" href="structXQC__Expression__s.html">XQC_Expression</a> *expr;
|
|
<a name="_a13"></a><a class="code" href="structXQC__DynamicContext__s.html">XQC_DynamicContext</a> *context;
|
|
<a name="_a14"></a><a class="code" href="structXQC__Sequence__s.html">XQC_Sequence</a> *seq, *doc;
|
|
<a class="code" href="xqc_8h.html#a66">XQC_Error</a> err;
|
|
<span class="keyword">const</span> <span class="keywordtype">char</span> *value;
|
|
|
|
<span class="comment">// XQilla specific way to create an XQC_Implementation struct</span>
|
|
impl = <a name="a15"></a><a class="code" href="xqilla-xqc_8h.html#a0">createXQillaXQCImplementation</a>(XQC_VERSION_NUMBER);
|
|
<span class="keywordflow">if</span>(impl == 0) <span class="keywordflow">return</span> 1;
|
|
|
|
<span class="comment">// Parse an XQuery expression</span>
|
|
err = impl-><a name="a16"></a><a class="code" href="structXQC__Implementation__s.html#z0_1">prepare</a>(impl, <span class="stringliteral">"foo/bar/@baz"</span>, 0, &expr);
|
|
<span class="keywordflow">if</span>(err != 0) <span class="keywordflow">goto</span> free_impl;
|
|
|
|
<span class="comment">// Parse a document</span>
|
|
err = impl-><a name="a17"></a><a class="code" href="structXQC__Implementation__s.html#z1_0">parse_document</a>(impl, <span class="stringliteral">"<foo><bar baz='hello'/></foo>"</span>, &doc);
|
|
<span class="keywordflow">if</span>(err != 0) <span class="keywordflow">goto</span> free_expr;
|
|
|
|
<span class="comment">// Create a dynamic context</span>
|
|
err = expr-><a name="a18"></a><a class="code" href="structXQC__Expression__s.html#o0">create_context</a>(expr, &context);
|
|
<span class="keywordflow">if</span>(err != 0) <span class="keywordflow">goto</span> free_doc;
|
|
|
|
<span class="comment">// Set the document as the context item</span>
|
|
doc-><a name="a19"></a><a class="code" href="structXQC__Sequence__s.html#o0">next</a>(doc);
|
|
context-><a name="a20"></a><a class="code" href="structXQC__DynamicContext__s.html#o2">set_context_item</a>(context, doc);
|
|
|
|
<span class="comment">// Execute the query</span>
|
|
err = expr-><a name="a21"></a><a class="code" href="structXQC__Expression__s.html#o1">execute</a>(expr, context, &seq);
|
|
<span class="keywordflow">if</span>(err != 0) <span class="keywordflow">goto</span> free_context;
|
|
|
|
<span class="comment">// Iterate over the results, printing them</span>
|
|
<span class="keywordflow">while</span>((err = seq-><a class="code" href="structXQC__Sequence__s.html#o0">next</a>(seq)) == XQC_NO_ERROR) {
|
|
seq-><a name="a22"></a><a class="code" href="structXQC__Sequence__s.html#z3_2">string_value</a>(seq, &value);
|
|
printf(<span class="stringliteral">"%s\n"</span>, value);
|
|
}
|
|
|
|
<span class="keywordflow">if</span>(err == XQC_END_OF_SEQUENCE)
|
|
err = XQC_NO_ERROR;
|
|
|
|
<span class="comment">// free everything</span>
|
|
seq-><a name="a23"></a><a class="code" href="structXQC__Sequence__s.html#o2">free</a>(seq);
|
|
free_context:
|
|
context-><a name="a24"></a><a class="code" href="structXQC__DynamicContext__s.html#o9">free</a>(context);
|
|
free_doc:
|
|
doc-><a class="code" href="structXQC__Sequence__s.html#o2">free</a>(doc);
|
|
free_expr:
|
|
expr-><a name="a25"></a><a class="code" href="structXQC__Expression__s.html#o3">free</a>(expr);
|
|
free_impl:
|
|
impl-><a name="a26"></a><a class="code" href="structXQC__Implementation__s.html#o1">free</a>(impl);
|
|
|
|
<span class="keywordflow">return</span> err;
|
|
}
|
|
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Fri Sep 25 06:55:57 2009 for XQilla XQC API by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
|
|
</body>
|
|
</html>
|