<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>
<aname="_a1"></a><aclass="code"href="structXQC__Expression__s.html"title="The XQC_Expression struct represents a prepared query, and allows the user to execute that query any ...">XQC_Expression</a> *expr;
<aclass="code"href="xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3f"title="The error enumeration used by all XQC functions to designate error condition.">XQC_Error</a> err;
impl = <aname="a4"></a><aclass="code"href="xqilla-xqc_8h.html#acd9659e93bbfafcd0cac9d7c4c12e13c"title="Creates an XQC_Implementation object that uses XQilla.">createXQillaXQCImplementation</a>(<aname="a5"></a><aclass="code"href="xqc_8h.html#a8fbc00dfcf0a3527e0ccba36322e1c84"title="The version of the XQC API in this header file.">XQC_VERSION_NUMBER</a>);
err = impl-><aname="a6"></a><aclass="code"href="structXQC__Implementation__s.html#a4f82aa0b0e5c675f95f6c78b3bf76216"title="Prepares a query from a UTF-8 string, returning an XQC_Expression object.">prepare</a>(impl, <spanclass="stringliteral">"foo/bar/@baz"</span>, 0, &expr);
err = expr-><aname="a8"></a><aclass="code"href="structXQC__Expression__s.html#a04be56651df9f3f47aecd99a0b0ad66e"title="Creates a dynamic context suitable for use in the execute() function.">create_context</a>(expr, &context);
doc-><aname="a9"></a><aclass="code"href="structXQC__Sequence__s.html#ab84594b06f7e69fd870c41f55ae5c6c6"title="Moves the XQC_Sequence so that the current item is positioned at the next item in the sequence...">next</a>(doc);
context-><aname="a10"></a><aclass="code"href="structXQC__DynamicContext__s.html#a0c69d262bfe4fd038832db4e4db600af"title="Sets the context item to the current item of the XQC_Sequence given.">set_context_item</a>(context, doc);
err = expr-><aname="a11"></a><aclass="code"href="structXQC__Expression__s.html#a3181579fa2677d43c29efd31a649726c"title="Executes the query represented by the XQC_Expression object using the values in the XQC_DynamicContex...">execute</a>(expr, context, &seq);
<spanclass="keywordflow">while</span>((err = seq-><aclass="code"href="structXQC__Sequence__s.html#ab84594b06f7e69fd870c41f55ae5c6c6"title="Moves the XQC_Sequence so that the current item is positioned at the next item in the sequence...">next</a>(seq)) == <aname="a12"></a><aclass="code"href="xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fa975a11c6557d4d849e48f4034380a375"title="No error.">XQC_NO_ERROR</a>) {
seq-><aname="a13"></a><aclass="code"href="structXQC__Sequence__s.html#a3bd3b6dab0c68652af816438407dd037"title="Returns the string value of the current item in the sequence - this is equivalent to calling fn:strin...">string_value</a>(seq, &value);
<spanclass="keywordflow">if</span>(err == <aname="a14"></a><aclass="code"href="xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fadfd1d8eea45c90655b98cfd728bfee2e"title="The end of the XQC_Sequence has been reached.">XQC_END_OF_SEQUENCE</a>)
seq-><aname="a15"></a><aclass="code"href="structXQC__Sequence__s.html#a13ab651edb4e0754cb8a032e2bce50b0"title="Called to free the resources associated with the XQC_Sequence.">free</a>(seq);
context-><aname="a16"></a><aclass="code"href="structXQC__DynamicContext__s.html#ad40117a7e2dd660ea7478c4cc5124eab"title="Called to free the resources associated with the XQC_DynamicContext.">free</a>(context);
doc-><aclass="code"href="structXQC__Sequence__s.html#a13ab651edb4e0754cb8a032e2bce50b0"title="Called to free the resources associated with the XQC_Sequence.">free</a>(doc);
expr-><aname="a17"></a><aclass="code"href="structXQC__Expression__s.html#a6aa28a94f0ff6732c26f131bbe4d44a9"title="Called to free the resources associated with the XQC_Expression.">free</a>(expr);
impl-><aname="a18"></a><aclass="code"href="structXQC__Implementation__s.html#afb636b6cbd236831652a518d9e71418d"title="Called to free the resources associated with the XQC_Implementation.">free</a>(impl);