server-php-xml-class-path-parser-class-path-parser.htm / htm
<html> <head> <title>Path Parser (class_path_parser.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">Path Parser (class_path_parser.php)</td> </tr> <tr> <td bgcolor="#aaaaee" class="textblbl" align="center"><a href="http://www.sourceforge.net/projects/phpxmlclasses">Downloads at Sourceforge</a></td> </tr> </table> <br/> <table border="0" width="80%"> <tr> <td bgcolor="#eeeeff" class="text">Description: A generic XML parsing class that lets your set-up PHP functions to be called when some XML elements are found. <br/>Using this class you can set handlers for specific XML paths, for example /foo/data/name, for each handler you set up a PHP function in the form foo(attribs,<br/> Summarizing this is a good tool to generalize parsing tasks using SAX/expat from PHP. It can be used as a generic parsing class and is specially useful to retrieve elements from a very large file before processing each element using DOM. (We've parsed 50Mb XML documents with success using this class). </td> </tr> </table> <br/> <table border="0" bgcolor="ddddff" width="80%"> <tr> <td valign="top" class="text" width="50%"><b>NEWS:</b> <ul> <li> 06-20-2002 First version of this class released. </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/path_parser/">Browse CVS</a> <li><a class="textbl" href="http://sourceforge.net/tracker/?atid=470965&group_id=53613&func=browse">Report Bugs</a> </ul> </td> <td valign="top" bgcolor="eeeeff" class="text" width="50%"> <ul> <li>PHP 4.0.5+ </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>Absolute paths can be parsed. <li>Multiple handlers can be set, a handler can handle multiple paths. <li>Namespaces are supported (local name can be used regardless of the namespace) </ul> </td> <td valign="top" bgcolor="ddddff" class="text" width="50%"> <ul> <li>Support for paths with wildcards is planned example //name or /foo//name </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"> <b>Detailed description and usage:</b> <br/><br/> See path_parser.php for an example about how to use the class, this is the code: <br/><br/> <pre> include_once("class_path_parser.php"); function name(name,content) { print("<br/>"); print("Hey <br/>\n"); print_r(attribs); print("<br/>"); } parser->set_handler("/foo/data/name","name"); parser->set_handler("/foo/data/type/var","name"); if(!parser->get_error()."<br/>\n"); } </pre> <br/><br/> As you can see using this class is very easy and can provide a lot of very good results. If the document uses namespaces you can set-up paths based on local-names. (A handler setting paths using qualified names is planned for a future release) </div> <h3>Documentation</h3> <h2>Classes</h2> <ul> <li><a href="#class31">Path_parser</a></li> </ul> <a name="class31"></a> <h3>Path_parser</h3> Extends: None
Description: Using this class you can parse an XML file setting handlers for specific XML elements defined by paths, for example /foo/data/name or /foo/data, the handlers can receive the element name, attributes and content. This class can be used in several ways incresing XML processing felxibility a lot.
<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> string</CODE></FONT></TD> <TD><CODE><B><A HREF="#class31method1">get_error</A></B>()</CODE> <BR> Returns last error message</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="#class31method2">init</A></B>()</CODE> <BR> Initializes the parser</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="#class31method3">parse_file</A></B>(string data, boolean path, string xml)</PRE> <DL> <DD>This method can be used to parse an XML document from a file or URL<DD> <DL> <DT><B>Parameters:</B><DD> <br><DT><B>Returns:</B><DD>True if the document was parsed succesfully, false if there was some error.<DT><B>Throws:</B><DD><CODE>If an error occurss this method sets an error message that can be recovered with get_error</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class31method4"><!-- --></A> <H3>parse</H3> <PRE> boolean <B>parse</B>(string data, boolean data - This should contain a chunk of XML data to be parsed<br><br><DT><B>Returns:</B><DD>True if the data was parsed succesfully or false if there was some error<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class31method5"><!-- --></A> <H3>set_handler</H3> <PRE> void <B>set_handler</B>(string path, string path - This is an absolute path from the roor of the XML document for example /foo/data/name will match name elements children of data children of foo (foo is the root element).<br>name,content. attribs is an array of asocs containing the element attributes and <br><DT><B>Returns:</B><DD>Nothing<DT><B>Throws:</B><DD><CODE>None</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.