PHP Class XML_Parser

This is an XML parser based on PHP's "xml" extension, based on the bundled expat library. Notes: - It requires PHP 4.0.4pl1 or greater - From revision 1.17, the function names used by the 'func' mode are in the format "xmltag_$elem", for example: use "xmltag_name" to handle the tags of your xml file.
Author: Stig Bakken ([email protected])
Author: Tomas V.V.Cox ([email protected])
Author: Stephan Schmidt ([email protected])
Inheritance: extends PEAR
Afficher le fichier Open project: sourcefabric/newscoop Class Usage Examples

Méthodes publiques

Свойство Type Description
$_handlerObj object handler object
$_validEncodings array valid encodings
$folding boolean If set to true, all tag and attribute names will be converted to UPPER CASE.
$fp resource File handle if parsing from a file
$handler array Mapping from expat handler function to class method.
$mode string Mode of operation, one of "event" or "func"
$parser resource XML parser handle
$srcenc string source encoding
$tgtenc string target encoding

Méthodes publiques

Méthode Description
XML_Parser ( string $srcenc = null, string $mode = 'event', string $tgtenc = null ) Creates an XML parser.
__construct ( string $srcenc = null, string $mode = 'event', string $tgtenc = null ) PHP5 constructor
_create ( ) : boolean | PEAR_Error create the XML parser resource
_initHandlers ( ) : mixed Init the element handlers
_parseString ( string $data, boolean $eof = false ) : boolean XML_Parser::_parseString()
endHandler ( mixed $xp, mixed $elem ) : null abstract method signature for End Handler
free ( ) : null XML_Parser::free()
funcEndHandler ( mixed $xp, mixed $elem ) : void derives and calls the End Handler function
funcStartHandler ( mixed $xp, mixed $elem, mixed $attribs ) : void derives and calls the Start Handler function
parse ( ) : boolean | PEAR_Error Central parsing function.
parseString ( string $data, boolean $eof = false ) : boolean | PEAR_Error XML_Parser::parseString()
raiseError ( $message = NULL, integer $ecode = NULL, $mode = NULL, $options = NULL, $userinfo = NULL, $error_class = NULL, $skipmsg = false ) : XML_Parser_Error XML_Parser::raiseError()
reset ( ) : boolean | object Reset the parser.
setHandlerObj ( &$obj ) : boolean Sets the object, that will handle the XML events
setInput ( mixed $fp ) : mixed Sets the file handle to use with parse().
setInputFile ( string $file ) : resource Sets the input xml file to be parsed
setInputString ( string $data ) : null XML_Parser::setInputString()
setMode ( string $mode ) : boolean | object Sets the mode of the parser.
startHandler ( mixed $xp, mixed $elem, &$attribs ) : null abstract method signature for Start Handler

Method Details

XML_Parser() public méthode

This is needed for PHP4 compatibility, it will call the constructor, when a new instance is created.
public XML_Parser ( string $srcenc = null, string $mode = 'event', string $tgtenc = null )
$srcenc string source charset encoding, use NULL (default) to use whatever the document specifies
$mode string how this parser object should work, "event" for startelement/endelement-type events, "func" to have it call functions named after elements
$tgtenc string a valid target encoding

__construct() public méthode

PHP5 constructor
public __construct ( string $srcenc = null, string $mode = 'event', string $tgtenc = null )
$srcenc string source charset encoding, use NULL (default) to use whatever the document specifies
$mode string how this parser object should work, "event" for startelement/endelement-type events, "func" to have it call functions named after elements
$tgtenc string a valid target encoding

_create() public méthode

Has been moved from the constructor to avoid problems with object references. Furthermore it allows us returning an error if something fails. NOTE: uses '@' error suppresion in this method
See also: xml_parser_create
public _create ( ) : boolean | PEAR_Error
Résultat boolean | PEAR_Error true on success, PEAR_Error otherwise

_initHandlers() public méthode

Init the element handlers
public _initHandlers ( ) : mixed
Résultat mixed

_parseString() public méthode

XML_Parser::_parseString()
See also: parseString()
public _parseString ( string $data, boolean $eof = false ) : boolean
$data string data
$eof boolean end-of-file flag
Résultat boolean

endHandler() public méthode

abstract method signature for End Handler
public endHandler ( mixed $xp, mixed $elem ) : null
$xp mixed ??
$elem mixed ??
Résultat null

free() public méthode

Free the internal resources associated with the parser
public free ( ) : null
Résultat null

funcEndHandler() public méthode

derives and calls the End Handler function
public funcEndHandler ( mixed $xp, mixed $elem ) : void
$xp mixed ??
$elem mixed ??
Résultat void

funcStartHandler() public méthode

derives and calls the Start Handler function
public funcStartHandler ( mixed $xp, mixed $elem, mixed $attribs ) : void
$xp mixed ??
$elem mixed ??
$attribs mixed ??
Résultat void

parse() public méthode

Central parsing function.
public parse ( ) : boolean | PEAR_Error
Résultat boolean | PEAR_Error returns true on success, or a PEAR_Error otherwise

parseString() public méthode

Parses a string.
See also: _parseString()
public parseString ( string $data, boolean $eof = false ) : boolean | PEAR_Error
$data string XML data
$eof boolean If set and TRUE, data is the last piece of data sent in this parser
Résultat boolean | PEAR_Error true on success or a PEAR Error

raiseError() public méthode

Throws a XML_Parser_Error
public raiseError ( $message = NULL, integer $ecode = NULL, $mode = NULL, $options = NULL, $userinfo = NULL, $error_class = NULL, $skipmsg = false ) : XML_Parser_Error
$ecode integer the error message code
Résultat XML_Parser_Error reference to the error object

reset() public méthode

This allows you to use one parser instance to parse multiple XML documents.
public reset ( ) : boolean | object
Résultat boolean | object true on success, PEAR_Error otherwise

setHandlerObj() public méthode

This allows you to create a handler object independent of the parser object that you are using and easily switch the underlying parser. If no object will be set, XML_Parser assumes that you extend this class and handle the events in $this.
public setHandlerObj ( &$obj ) : boolean
Résultat boolean will always return true

setInput() public méthode

You should use setInputFile() or setInputString() if you pass a string
See also: parse()
public setInput ( mixed $fp ) : mixed
$fp mixed Can be either a resource returned from fopen(), a URL, a local filename or a string.
Résultat mixed

setInputFile() public méthode

Sets the input xml file to be parsed
public setInputFile ( string $file ) : resource
$file string Filename (full path)
Résultat resource fopen handle of the given file

setInputString() public méthode

Sets the xml input from a string
public setInputString ( string $data ) : null
$data string a string containing the XML document
Résultat null

setMode() public méthode

Possible modes are: - func - event You can set the mode using the second parameter in the constructor. This method is only needed, when switching to a new mode at a later point.
public setMode ( string $mode ) : boolean | object
$mode string mode, either 'func' or 'event'
Résultat boolean | object true on success, PEAR_Error otherwise

startHandler() public méthode

abstract method signature for Start Handler
public startHandler ( mixed $xp, mixed $elem, &$attribs ) : null
$xp mixed ??
$elem mixed ??
Résultat null

Property Details

$_handlerObj public_oe property

handler object
public object $_handlerObj
Résultat object

$_validEncodings public_oe property

valid encodings
public array $_validEncodings
Résultat array

$folding public_oe property

If set to true, all tag and attribute names will be converted to UPPER CASE.
public bool $folding
Résultat boolean

$fp public_oe property

File handle if parsing from a file
public resource $fp
Résultat resource

$handler public_oe property

Mapping from expat handler function to class method.
public array $handler
Résultat array

$mode public_oe property

Mode of operation, one of "event" or "func"
public string $mode
Résultat string

$parser public_oe property

XML parser handle
See also: xml_parser_create()
public resource $parser
Résultat resource

$srcenc public_oe property

source encoding
public string $srcenc
Résultat string

$tgtenc public_oe property

target encoding
public string $tgtenc
Résultat string