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 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 >
2020-02-17 21:19:08 +00:00
<!-- 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 >
2020-02-17 21:17:06 +00:00
< 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[])
{
2020-02-17 21:19:08 +00:00
< 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;
2020-02-17 21:17:06 +00:00
< span class = "keyword" > const< / span > < span class = "keywordtype" > char< / span > *value;
< span class = "comment" > // XQilla specific way to create an XQC_Implementation struct< / span >
2020-02-17 21:19:08 +00:00
impl = < a name = "a15" > < / a > < a class = "code" href = "xqilla-xqc_8h.html#a0" > createXQillaXQCImplementation< / a > (XQC_VERSION_NUMBER);
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > if< / span > (impl == 0) < span class = "keywordflow" > return< / span > 1;
< span class = "comment" > // Parse an XQuery expression< / span >
2020-02-17 21:19:08 +00:00
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);
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > if< / span > (err != 0) < span class = "keywordflow" > goto< / span > free_impl;
< span class = "comment" > // Parse a document< / span >
2020-02-17 21:19:08 +00:00
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);
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > if< / span > (err != 0) < span class = "keywordflow" > goto< / span > free_expr;
< span class = "comment" > // Create a dynamic context< / span >
2020-02-17 21:19:08 +00:00
err = expr-> < a name = "a18" > < / a > < a class = "code" href = "structXQC__Expression__s.html#o0" > create_context< / a > (expr, & context);
2020-02-17 21:17:06 +00:00
< 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 >
2020-02-17 21:19:08 +00:00
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);
2020-02-17 21:17:06 +00:00
< span class = "comment" > // Execute the query< / span >
2020-02-17 21:19:08 +00:00
err = expr-> < a name = "a21" > < / a > < a class = "code" href = "structXQC__Expression__s.html#o1" > execute< / a > (expr, context, & seq);
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > if< / span > (err != 0) < span class = "keywordflow" > goto< / span > free_context;
< span class = "comment" > // Iterate over the results, printing them< / span >
2020-02-17 21:19:08 +00:00
< 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);
2020-02-17 21:17:06 +00:00
printf(< span class = "stringliteral" > "%s\n"< / span > , value);
}
2020-02-17 21:19:08 +00:00
< span class = "keywordflow" > if< / span > (err == XQC_END_OF_SEQUENCE)
err = XQC_NO_ERROR;
2020-02-17 21:17:06 +00:00
< span class = "comment" > // free everything< / span >
2020-02-17 21:19:08 +00:00
seq-> < a name = "a23" > < / a > < a class = "code" href = "structXQC__Sequence__s.html#o2" > free< / a > (seq);
2020-02-17 21:17:06 +00:00
free_context:
2020-02-17 21:19:08 +00:00
context-> < a name = "a24" > < / a > < a class = "code" href = "structXQC__DynamicContext__s.html#o9" > free< / a > (context);
2020-02-17 21:17:06 +00:00
free_doc:
2020-02-17 21:19:08 +00:00
doc-> < a class = "code" href = "structXQC__Sequence__s.html#o2" > free< / a > (doc);
2020-02-17 21:17:06 +00:00
free_expr:
2020-02-17 21:19:08 +00:00
expr-> < a name = "a25" > < / a > < a class = "code" href = "structXQC__Expression__s.html#o3" > free< / a > (expr);
2020-02-17 21:17:06 +00:00
free_impl:
2020-02-17 21:19:08 +00:00
impl-> < a name = "a26" > < / a > < a class = "code" href = "structXQC__Implementation__s.html#o1" > free< / a > (impl);
2020-02-17 21:17:06 +00:00
< span class = "keywordflow" > return< / span > err;
}
2020-02-17 21:19:08 +00:00
< / pre > < / div > < hr size = "1" > < address style = "align: right;" > < small > Generated on Fri Sep 25 06:55:57 2009 for XQilla XQC API by
2020-02-17 21:17:06 +00:00
< a href = "http://www.doxygen.org/index.html" >
2020-02-17 21:19:08 +00:00
< img src = "doxygen.png" alt = "doxygen" align = "middle" border = "0" > < / a > 1.3.9.1 < / small > < / address >
2020-02-17 21:17:06 +00:00
< / body >
< / html >