Class for parsing XML documents using SAX
This class is a abstraction class for the PHP Expat XML functions.
You can define handler functions/objects for start, end, PI and data sections (1.) or your can define path which will trigger the defined event when encountered (2.)
Example:
1.) $parser->setEvents(array("startElement"=> "myFunction", "endElement"=> "myFunction", "characterData"=> "myFunction", "processingInstruction" => "myFunction"); The value can also be an array with the object reference and the method to call. i.e. "startElement"=>array(&$myObj, "myMethod") instead of "startelement"=>"myFunction" 2.) $parser->setEvents(array("/root/foo/bar"=>"myFunction")); Valid array keys are: 'startElement', 'endElement', 'characterData', 'processingInstruction' and paths folowing the scheme '/root/element'. The path MUST begin from the root element and MUST start with '/'. The value can also be an array with the object reference and the method to call. i.e. "/foo/bar"=>array(&$myObj, "myMethod") instead of "/foo/bar"=>"myFunction" It has 3 public methods: setEventHandlers - Set specific handlers for the xml parser parseFile - Used to parse a XML file parse - Used to parse a XML string A small example: include("class.xmlparser.php"); // The XML String $xml = ''; function myHandler($name, $attribs, $content) { echo "HIT: [ $name ] [ $content ] some text another text
"; } $parser = new XmlParser(); // Parser instance $parser->setEventHandlers(array("/foo/bar"=>"myHandler")); // Define our handler $parser->parse($xml); // Parse the XML string
Report bugs to: jan.lengowski@4fb.de
author | Jan Lengowski <Jan.Lengowski@4fb.de> |
---|---|
copyright | four for business AG |
version | 1.0 |
package | CONTENIDO Backend Classes |
deprecated | 2012-08-24 Use cXmlReader instead |
XmlParser(string $sEncoding) : void
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
Encoding used when parsing files (default: UTF-8, as in PHP5)
_addPath(string $depth, $name) : void
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
Element node name
_changeKeyCase(array $options) : array
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
array
Source array
array
Array with lowercased keys_characterData(resource $parser, string $data) : void
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
resource
XML Parser resource
string
XML node data
_endElement(resource $parser, string $name) : void
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
resource
XML Parser resource
string
XML Element node name
_error() : string
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
XML Error message_getActivePath()
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
_getDefinedPaths(array $options) : array
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
array
Options array
array
Paths array_getEventHandler(string $event) : \sring
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
Event type
\sring
Event handler name_init(string $sEncoding) : void
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
Encoding used when parsing files (default: UTF-8, as in PHP5)
_processingInstruction(string $parser, $target, $data) : void
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
Processing instruction handler
_startElement(resource $parser, string $name, array $attribs) : void
access | private |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
resource
XML Parser resource
string
XML Element node name
array
XML Element node attributes
parse(string $data, $final) : bool
access | public |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
XML data
bool
parseFile(string $file) : bool
access | public |
---|---|
deprecated | 2012-08-24 Use cXmlReader instead |
string
File location
bool
setEventHandlers(array $options) : void
You can define handler functions/objects for start, end, PI and data sections (1.) or your can define path which will trigger the defined event when encountered (2.)
Example:
1.) $parser->setEvents(array("startElement" => "myFunction", "endElement" => "myFunction", "characterData" => "myFunction", "processingInstruction" => "myFunction");
The value can also be an array with the object reference and the method to call. i.e. "startElement"=>array(&$myObj, "myMethod") instead of "startelement"=>"myFunction"
2.) $parser->setEvents(array("/root/foo/bar"=>"myFunction"));
Valid array keys are: 'startElement', 'endElement', 'characterData', 'processingInstruction' and paths folowing the scheme '/root/element'. The path MUST begin from the root element and MUST start with '/'.
The value can also be an array with the object reference and the method to call. i.e. "/foo/bar"=>array(&$myObj, "myMethod") instead of "/foo/bar"=>"myFunction"
deprecated | 2012-08-24 Use cXmlReader instead |
---|
array
Options array, valid keys are 'startElement', 'endElement', 'characterData', 'processingInstruction', or a path
$activenode : string
access | private |
---|
$activepath : string
access | private |
---|
$autofree : bool
$count : int
access | private |
---|
$depth : int
access | private |
---|
$error : string
access | private |
---|
$events : array
access | private |
---|
$parser : object
access | private |
---|
$pathdata : array
access | private |
---|
$paths : array
access | private |
---|
$pcount : int
access | private |
---|