topical media & game development
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,name,content) {
print("<br/>");
print("Hey 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>
data, boolean data - This should contain a chunk of XML data to be parsed<br>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
(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.