server-php-xml-class-xquery-lite-class-xquery-lite.htm / htm
<html> <head> <title>XQuery Lite (class_xquery_lite.php)</title> <link rel="stylesheet" href="main.css" type="text/css"> </head> <body> <div align="center"> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#aaaaee" class="text" align="center"><a href="http://phpxmlclasses.sourceforge.net/">PHP XML Classes</a></td> </tr> </table> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#aaaaee" class="textblbl" align="center">XqueryLite (class_xquery_lite.php)</td> </tr> </table> <br/> <table border="0" width="80%"> <tr> <td bgcolor="#eeeeff" class="text">Description: This is a PHP implementation of the <a href="xquery_lite.html">Xquery Lite</a> language for XML query. This implementation is based on the PHP DOM extension (it uses Xpath). It is 100% compatible with Xquery Lite. </td> </tr> </table> <br/> <table border="0" bgcolor="ddddff" width="80%"> <tr> <td valign="top" class="text" width="50%"><b>NEWS:</b> <ul> <li>First release of this class </ul> </td> <td valign="top" width="50%" class="text"> This class code as well as documentation are hosted at <a href="http://www.sourceforge.net">SourceForge</a> please visit our <a href="http://www.sourceforge.net/projects/phpxmlclasses/">SourceForge page</a> for releases, documentation, bug-tracking, support forums and mailing lists. </td> </tr> </table> <br/> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td class="textbl" bgcolor="aaaaee" width="50%">Resources</td> <td class="textbl" bgcolor="aaaaee" width="50%">Requirements</td> </tr> </table> <table border="1" width="80%" cellpadding="0" cellspacing="0"> <tr> <td valign="top" bgcolor="eeeeff" class="text" width="50%"> <ul> <li><a class="textbl" href="http://www.sourceforge.net/projects/phpxmlclasses">Downloads</a> <li><a class="textbl" href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpxmlclasses/xquery_lite/">Browse CVS</a> <li><a class="textbl" href="http://sourceforge.net/tracker/?atid=470965&group_id=53613&func=browse">Report Bugs</a> <li><a class="textbl" href="http://phpxmlclasses.sourceforge.net/xquery_lite.html">Xquery Lite Tutorial</a> (<a class="textbl" href="http://phpxmlclasses.sourceforge.net/xquery_lite_1.0.pdf">pdf</a>) <li><a class="textbl" href="http://research.salutia.com/xquery_lite/demo.php">Demo Site</a> </ul> </td> <td valign="top" bgcolor="eeeeff" class="text" width="50%"> <ul> <li>PHP 4.2.1+ <li>DOM extension compiled </ul> </td> </tr> </table> <br/> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td class="textbl" bgcolor="aaaaee" width="50%">Features</td> <td class="textbl" bgcolor="aaaaee" width="50%">To-dos</td> </tr> </table> <table border="1" width="80%" cellpadding="0" cellspacing="0"> <tr> <td valign="top" bgcolor="eeeeff" class="text" width="50%"> <ul> <li>Xquery Lite 1.0 supported. </ul> </td> <td valign="top" bgcolor="ddddff" class="text" width="50%"> <ul> <li>Support the new release of the Xquery Lite language adding if statements, sortby statements and others. <li>Queries may be "unsafe" if the user may enter a query, so a small security check is needed in order to allow user-entered queries without a problem. </ul> </td> </tr> </table> <br/> <table border="0" bgcolor="ddddff" width="80%"> <tr> <!-- <td valign="top" class="text" width="50%"><b>To-do/future releases:</b> <ul> <li>Class <li>Class <li>Class </ul> </td> --> <td valign="top" width="100%" class="text"> Contact: Luis Argerich (<a href="mailto:lrargerich@yahoo.com">;lrargerich@yahoo.com</a>) </td> </tr> </table> <br/> <table border="0" bgcolor="ddddff" width="80%"> <tr> <!-- <td valign="top" class="text" width="50%"><b>To-do/future releases:</b> <ul> <li>Class <li>Class <li>Class </ul> </td> --> <td valign="top" width="100%" class="text"> Detailed description and usage: The usage of this class is easy, basically you just create an object and then use init to initialize the object and the evaluate_xqueryl method to process a qery: <pre>xq->init(); xq->evaluate_xqueryl(</pre> If you need to process a second query call the init method to reset object internal state to the initial state. In order to learn more about Xquery Lite and how to write a query please visit the <a href="xquery_lite.html">Xquery Lite home page</a> <br/> </div> <h3>Documentation</h3> <h2>Classes</h2> <ul> <li><a href="#class27">XqueryLite</a></li> </ul> <a name="class27"></a> <h3>XqueryLite</h3> Extends: None
Description: This class implements the Xquery Lite 1.0 language, a querying language for XML based on Xquery 1.0 using Xpath and FLWR expressions as the foundations.
<br> <!-- METHOD SUMMARY --> <A NAME="pDomNode_method_summary"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=2><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD> </TR> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> void</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method1">XqueryLite</A></B>()</CODE> <BR> Constructor</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> void</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method2">init</A></B>()</CODE> <BR> Initializes the object internal state to the initial state</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> string</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method3">evaluate_xqueryl</A></B>(string query)</CODE> <BR> Evaluates an Xquery Lite 1.0 query</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> array</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method4">_tokenize</A></B>(string node)</CODE> <BR> (PRIVATE) Returns the root tagname from a node</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> string</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method6">_parse_for</A></B>(string nodeset)</CODE> <BR> (PRIVATE) Filters a nodeset returning a nodeset without duplicate nodes</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> string</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method8">_normalize_elements</A></B>(object expr, boolean a/xpath_expr expression</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> int</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method10">_count_var</A></B>(string a/xpath_expr expression</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> boolean</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method11">_parse_where</A></B>(string expr)</CODE> <BR> (PRIVATE) Parses a return statement</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> void</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method13">_parse_let</A></B>(string exprs)</CODE> <BR> (PRIVATE) Split a for statement in several if it has to</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> string</CODE></FONT></TD> <TD><CODE><B><A HREF="#class27method15">_parse_query</A></B>(string query)</PRE> <DL> <DD>This method is used to evaluate an Xquery Lite 1.0 query, just pass the query as an argument and receive the result.<DD> <DL> <DT><B>Parameters:</B><DD> <br><DT><B>Returns:</B><DD>The result of the query whatever it is<DT><B>Throws:</B><DD><CODE>Several exceptions can be reaised as warnings if an error occurs when parsing the query, tipically the query has a syntax error or the XML source can't be located.</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method4"><!-- --></A> <H3>_tokenize</H3> <PRE> array <B>_tokenize</B>(string exp)</PRE> <DL> <DD>This private method receives a Xquery Lite expression (whatever is found between curly brackets) and returns an array of statements, for example v[0]=a for statament, v[1]=a let statement, v[2]=a where statement, v[3]=return statement.<DD> <DL> <DT><B>Parameters:</B><DD> <br><DT><B>Returns:</B><DD>An array where each array position contains an statement<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method5"><!-- --></A> <H3>_get_root_name</H3> <PRE> string <B>_get_root_name</B>(object node)</PRE> <DL> <DD>This method returns the name of the root element from an XML fragment passed as a node.<DD> <DL> <DT><B>Parameters:</B><DD> <br><DT><B>Returns:</B><DD>The name of the root element<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method6"><!-- --></A> <H3>_parse_for</H3> <PRE> string <B>_parse_for</B>(string expr)</PRE> <DL> <DD>This method parses a for statement and puts the nodeset resulting from the for statement in the object result_sets member.<DD> <DL> <DT><B>Parameters:</B><DD> <br><DT><B>Returns:</B><DD>The name of the Xquery variable corresponding to the for statement.<DT><B>Throws:</B><DD><CODE>It can raise an error if the XML source is not found, if it is not well formed or if the Xpath expression in the for statement is wrong</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method7"><!-- --></A> <H3>_distinct</H3> <PRE> array <B>_distinct</B>(array nodeset)</PRE> <DL> <DD>Filters a nodeset returning a nodeset without duplicate nodes, the normalize_elements function is used in order to compare nodes and find duplicate nodes in the nodeset.<DD> <DL> <DT><B>Parameters:</B><DD> <br><DT><B>Returns:</B><DD>An array of nodes (another nodeset) without duplicate nodes<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method8"><!-- --></A> <H3>_normalize_elements</H3> <PRE> string <B>_normalize_elements</B>(object node)</PRE> <DL> <DD>This function normalizes a dom subtree removing all whitespace elements thus producing a normalized representation of the subtree that can be used in comparisons.<DD> <DL> <DT><B>Parameters:</B><DD> <br><DT><B>Returns:</B><DD>An string containing a normalized dump of the subtree<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method9"><!-- --></A> <H3>_parse_var</H3> <PRE> string <B>_parse_var</B>(string expr, boolean a/xpath_expr where expr - The expression to be parsed<br><br><DT><B>Returns:</B><DD>A string representing the result, if the result is a nodeset then all nodes are concatenated one after the other.<DT><B>Throws:</B><DD><CODE>It can raise an exception if the xpath expression has an error or if the variable is not well formed XML</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method10"><!-- --></A> <H3>_count_var</H3> <PRE> int <B>_count_var</B>(string expr)</PRE> <DL> <DD>This method parses a expr - The expression<br><DT><B>Returns:</B><DD>The number of elements in the nodeset if no xpath expression is passed returns 1 if the variable exists if the nodeset is empty returns 0<DT><B>Throws:</B><DD><CODE>It can raise an error if the variable is not XML if it doesn't exist or it the Xpath expression is wrong.</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method11"><!-- --></A> <H3>_parse_where</H3> <PRE> boolean <B>_parse_where</B>(string expr - The where statement<br><DT><B>Returns:</B><DD>The result of the where expression<DT><B>Throws:</B><DD><CODE>If there's an error in the expression it raises an error</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method12"><!-- --></A> <H3>_parse_return</H3> <PRE> string <B>_parse_return</B>(string expr - The return statement, everything found from the return word to the end of the query, including the return word.<br><DT><B>Returns:</B><DD>The result of the return statement<DT><B>Throws:</B><DD><CODE>Several errors can be raised since this can potentially call evaluate_xqueryl</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method13"><!-- --></A> <H3>_parse_let</H3> <PRE> void <B>_parse_let</B>(string expr - The let statement<br><DT><B>Returns:</B><DD>nothing<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method14"><!-- --></A> <H3>_split_fors</H3> <PRE> array <B>_split_fors</B>(string exprs - A for statement in compact or extended notation<br><DT><B>Returns:</B><DD>An array where each element is a for statement<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class27method15"><!-- --></A> <H3>_parse_query</H3> <PRE> string <B>_parse_query</B>(string query - The Xquery Lite expression to be parsed<br><DT><B>Returns:</B><DD>The result of the query<DT><B>Throws:</B><DD><CODE>If there's an error when parsing the query</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- ============ METHOD DETAIL ========== --> </td> </tr> </table> </body> </html>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.