分类: LINUX
2005-11-11 18:37:55
PHP XML Classes
A collection of classes and resources to process XML using PHP
Description: This class implements a generic event-driven parser. User functions can be asociated to specific XML elements indicated by a path, for example /foo/data/name. Whenever the parser detects an element matching a path the user function is called receiving the element name, attributes and its content (xml fragment or text). A function can handle multiple paths or you can use one function for each path. This class can be used to process huge files processing element contents later with Xpath, DOM or XSLT. |
Path Parser (class_path_parser.php) |
Description: A generic XML parsing class that lets your set-up PHP functions
to be called when some XML elements are found. 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($name,$attribs,$content) that the parser will call when an element matching the given path is found by the parser. 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). |
NEWS:
|
This class code as well as documentation are hosted at please visit our for releases, documentation, bug-tracking, support forums and mailing lists. |
Resources | Requirements |
|
|
Features | To-dos |
|
|
Contact: Luis Argerich () |
include_once("class_path_parser.php");
function name($name,$attribs,$content) {
print("
");
print("Hey $name
");
print_r($attribs);
print("
");
}
$parser = new Path_parser();
$parser->set_handler("/foo/data/name","name");
$parser->set_handler("/foo/data","name");
$parser->set_handler("/foo/data/type/var","name");
if(!$parser->parse_file("foo.xml")) {
print("Error:".$parser->get_error()."
");
}
Method Summary | |
string |
()
Returns last error message |
void |
()
Initializes the parser |
boolean |
(string $xml)
Parses an XML document from a file or URL |
boolean |
(string $data, boolean $is_final)
Parses data |
void |
(string $path, string $handler_name)
Sets a handler to process XML elements |
Method Detail |
string get_error()
None
void init()
None
boolean parse_file(string $xml)
If an error occurss this method sets an error message that can be recovered with get_error
boolean parse(string $data, boolean $is_final)
None
void set_handler(string $path, string $handler_name)
None