XmlParser()
_addPath()
_changeKeyCase()
_characterData()
_endElement()
_error()
_getActivePath()
_getDefinedPaths()
_getEventHandler()
_init()
_processingInstruction()
_startElement()
parse()
parseFile()
setEventHandlers()
$activenode
$activepath
$autofree
$count
$depth
$error
$events
$parser
$pathdata
$paths
$pcount
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 ]<br/>"; }
$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 <www.4fb.de> |
version | 1.0 |
package | 4fb_XML |
XmlParser(string $sEncoding) : void
access | private |
---|
string
Encoding used when parsing files (default: UTF-8, as in PHP5)
_addPath(string $depth, $name) : void
access | private |
---|
string
Element node name
_changeKeyCase(array $options) : array
access | private |
---|
array
Source array
array
Array with lowercased keys_characterData(resource $parser, string $data) : void
access | private |
---|
resource
XML Parser resource
string
XML node data
_endElement(resource $parser, string $name) : void
access | private |
---|
resource
XML Parser resource
string
XML Element node name
_error() : string
access | private |
---|
string
XML Error message_getActivePath()
access | private |
---|
_getDefinedPaths(array $options) : array
access | private |
---|
array
Options array
array
Paths array_getEventHandler(string $event) : \sring
access | private |
---|
string
Event type
\sring
Event handler name_init(string $sEncoding) : void
access | private |
---|
string
Encoding used when parsing files (default: UTF-8, as in PHP5)
_processingInstruction(string $parser, $target, $data) : void
access | private |
---|
string
Processing instruction handler
_startElement(resource $parser, string $name, array $attribs) : void
access | private |
---|
resource
XML Parser resource
string
XML Element node name
array
XML Element node attributes
parse(string $data, $final) : bool
access | public |
---|
string
XML data
bool
parseFile(string $file) : bool
access | public |
---|
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"
access | public |
---|
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 |
---|