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:24:47 +00:00
<!-- Generated by Doxygen 1.8.5 -->
< div id = "navrow1" class = "tabs" >
< ul class = "tablist" >
< li > < a href = "index.html" > < span > Main  Page< / span > < / a > < / li >
2020-02-17 21:19:57 +00:00
< 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 >
2020-02-17 21:24:47 +00:00
< / div > <!-- top -->
< div class = "header" >
< div class = "headertitle" >
< div class = "title" > xqc-context-item.c< / div > < / div >
< / div > <!-- header -->
2020-02-17 21:19:57 +00:00
< div class = "contents" >
2020-02-17 21:24:47 +00:00
< 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" > < div class = "line" > < span class = "preprocessor" > #include < < a class = "code" href = "xqilla-xqc_8h.html" > xqilla/xqilla-xqc.h< / a > > < / span > < / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "keywordtype" > int< / span > main(< span class = "keywordtype" > int< / span > argc, < span class = "keywordtype" > char< / span > *argv[])< / div >
< div class = "line" > {< / div >
< div class = "line" > < a name = "_a0" > < / a > < a class = "code" href = "structXQC__Implementation__s.html" > XQC_Implementation< / a > *impl;< / div >
< div class = "line" > < a name = "_a1" > < / a > < a class = "code" href = "structXQC__Expression__s.html" > XQC_Expression< / a > *expr;< / div >
< div class = "line" > < a name = "_a2" > < / a > < a class = "code" href = "structXQC__DynamicContext__s.html" > XQC_DynamicContext< / a > *context;< / div >
< div class = "line" > < a name = "_a3" > < / a > < a class = "code" href = "structXQC__Sequence__s.html" > XQC_Sequence< / a > *seq, *doc;< / div >
< div class = "line" > < a class = "code" href = "xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3f" > XQC_Error< / a > err;< / div >
< div class = "line" > < span class = "keyword" > const< / span > < span class = "keywordtype" > char< / span > *value;< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // XQilla specific way to create an XQC_Implementation struct< / span > < / div >
< div class = "line" > impl = < a name = "a4" > < / a > < a class = "code" href = "xqilla-xqc_8h.html#acd9659e93bbfafcd0cac9d7c4c12e13c" > createXQillaXQCImplementation< / a > (< a name = "a5" > < / a > < a class = "code" href = "xqc_8h.html#a8fbc00dfcf0a3527e0ccba36322e1c84" > XQC_VERSION_NUMBER< / a > );< / div >
< div class = "line" > < span class = "keywordflow" > if< / span > (impl == 0) < span class = "keywordflow" > return< / span > 1;< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // Parse an XQuery expression< / span > < / div >
< div class = "line" > err = impl-> < a name = "a6" > < / a > < a class = "code" href = "structXQC__Implementation__s.html#a4f82aa0b0e5c675f95f6c78b3bf76216" > prepare< / a > (impl, < span class = "stringliteral" > " foo/bar/@baz" < / span > , 0, & expr);< / div >
< div class = "line" > < span class = "keywordflow" > if< / span > (err != 0) < span class = "keywordflow" > goto< / span > free_impl;< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // Parse a document< / span > < / div >
< div class = "line" > err = impl-> < a name = "a7" > < / a > < a class = "code" href = "structXQC__Implementation__s.html#a1e3a2cd7fdb4becb469d179bcb4c2396" > parse_document< / a > (impl, < span class = "stringliteral" > " < foo> < bar baz=' hello' /> < /foo> " < / span > , & doc);< / div >
< div class = "line" > < span class = "keywordflow" > if< / span > (err != 0) < span class = "keywordflow" > goto< / span > free_expr;< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // Create a dynamic context< / span > < / div >
< div class = "line" > err = expr-> < a name = "a8" > < / a > < a class = "code" href = "structXQC__Expression__s.html#a04be56651df9f3f47aecd99a0b0ad66e" > create_context< / a > (expr, & context);< / div >
< div class = "line" > < span class = "keywordflow" > if< / span > (err != 0) < span class = "keywordflow" > goto< / span > free_doc;< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // Set the document as the context item< / span > < / div >
< div class = "line" > doc-> < a name = "a9" > < / a > < a class = "code" href = "structXQC__Sequence__s.html#ab84594b06f7e69fd870c41f55ae5c6c6" > next< / a > (doc);< / div >
< div class = "line" > context-> < a name = "a10" > < / a > < a class = "code" href = "structXQC__DynamicContext__s.html#a0c69d262bfe4fd038832db4e4db600af" > set_context_item< / a > (context, doc);< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // Execute the query< / span > < / div >
< div class = "line" > err = expr-> < a name = "a11" > < / a > < a class = "code" href = "structXQC__Expression__s.html#a3181579fa2677d43c29efd31a649726c" > execute< / a > (expr, context, & seq);< / div >
< div class = "line" > < span class = "keywordflow" > if< / span > (err != 0) < span class = "keywordflow" > goto< / span > free_context;< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // Iterate over the results, printing them< / span > < / div >
< div class = "line" > < span class = "keywordflow" > while< / span > ((err = seq-> < a class = "code" href = "structXQC__Sequence__s.html#ab84594b06f7e69fd870c41f55ae5c6c6" > next< / a > (seq)) == < a name = "a12" > < / a > < a class = "code" href = "xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fa975a11c6557d4d849e48f4034380a375" > XQC_NO_ERROR< / a > ) {< / div >
< div class = "line" > seq-> < a name = "a13" > < / a > < a class = "code" href = "structXQC__Sequence__s.html#a3bd3b6dab0c68652af816438407dd037" > string_value< / a > (seq, & value);< / div >
< div class = "line" > printf(< span class = "stringliteral" > " %s\n" < / span > , value);< / div >
< div class = "line" > }< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "keywordflow" > if< / span > (err == < a name = "a14" > < / a > < a class = "code" href = "xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fadfd1d8eea45c90655b98cfd728bfee2e" > XQC_END_OF_SEQUENCE< / a > )< / div >
< div class = "line" > err = < a class = "code" href = "xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fa975a11c6557d4d849e48f4034380a375" > XQC_NO_ERROR< / a > ;< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "comment" > // free everything< / span > < / div >
< div class = "line" > seq-> < a name = "a15" > < / a > < a class = "code" href = "structXQC__Sequence__s.html#a13ab651edb4e0754cb8a032e2bce50b0" > free< / a > (seq);< / div >
< div class = "line" > free_context:< / div >
< div class = "line" > context-> < a name = "a16" > < / a > < a class = "code" href = "structXQC__DynamicContext__s.html#ad40117a7e2dd660ea7478c4cc5124eab" > free< / a > (context);< / div >
< div class = "line" > free_doc:< / div >
< div class = "line" > doc-> < a class = "code" href = "structXQC__Sequence__s.html#a13ab651edb4e0754cb8a032e2bce50b0" > free< / a > (doc);< / div >
< div class = "line" > free_expr:< / div >
< div class = "line" > expr-> < a name = "a17" > < / a > < a class = "code" href = "structXQC__Expression__s.html#a6aa28a94f0ff6732c26f131bbe4d44a9" > free< / a > (expr);< / div >
< div class = "line" > free_impl:< / div >
< div class = "line" > impl-> < a name = "a18" > < / a > < a class = "code" href = "structXQC__Implementation__s.html#afb636b6cbd236831652a518d9e71418d" > free< / a > (impl);< / div >
< div class = "line" > < / div >
< div class = "line" > < span class = "keywordflow" > return< / span > err;< / div >
< div class = "line" > }< / div >
< / div > <!-- fragment --> < / div > <!-- contents -->
<!-- start footer part -->
< hr class = "footer" / > < address class = "footer" > < small >
Generated by   < a href = "http://www.doxygen.org/index.html" >
< img class = "footer" src = "doxygen.png" alt = "doxygen" / >
< / a > 1.8.5
< / small > < / address >
2020-02-17 21:17:06 +00:00
< / body >
< / html >