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 = '
some text
another text
';
function myHandler($name, $attribs, $content) {
echo "HIT: [ $name ] [ $content ]
";
}
$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 |
stringEncoding used when parsing files (default: UTF-8, as in PHP5)
_addPath(string $depth, $name) : void
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
stringElement node name
_changeKeyCase(array $options) : array
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
arraySource array
arrayArray with lowercased keys_characterData(resource $parser, string $data) : void
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
resourceXML Parser resource
stringXML node data
_endElement(resource $parser, string $name) : void
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
resourceXML Parser resource
stringXML Element node name
_error() : string
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
stringXML 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 |
arrayOptions array
arrayPaths array_getEventHandler(string $event) : \sring
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
stringEvent type
\sringEvent handler name_init(string $sEncoding) : void
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
stringEncoding 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 |
stringProcessing instruction handler
_startElement(resource $parser, string $name, array $attribs) : void
| access | private |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
resourceXML Parser resource
stringXML Element node name
arrayXML Element node attributes
parse(string $data, $final) : bool
| access | public |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
stringXML data
boolparseFile(string $file) : bool
| access | public |
|---|---|
| deprecated | 2012-08-24 Use cXmlReader instead |
stringFile location
boolsetEventHandlers(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 |
|---|
arrayOptions 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 |
|---|