PHP Класс 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.
Автор: Stig Bakken ([email protected])
Автор: Tomas V.V.Cox ([email protected])
Автор: Stephan Schmidt ([email protected])
Наследование: extends PEAR
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$_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

Открытые методы

Метод Описание
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

Описание методов

XML_Parser() публичный Метод

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() публичный Метод

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() публичный Метод

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
См. также: xml_parser_create
public _create ( ) : boolean | PEAR_Error
Результат boolean | PEAR_Error true on success, PEAR_Error otherwise

_initHandlers() публичный Метод

Init the element handlers
public _initHandlers ( ) : mixed
Результат mixed

_parseString() публичный Метод

XML_Parser::_parseString()
См. также: parseString()
public _parseString ( string $data, boolean $eof = false ) : boolean
$data string data
$eof boolean end-of-file flag
Результат boolean

endHandler() публичный Метод

abstract method signature for End Handler
public endHandler ( mixed $xp, mixed $elem ) : null
$xp mixed ??
$elem mixed ??
Результат null

free() публичный Метод

Free the internal resources associated with the parser
public free ( ) : null
Результат null

funcEndHandler() публичный Метод

derives and calls the End Handler function
public funcEndHandler ( mixed $xp, mixed $elem ) : void
$xp mixed ??
$elem mixed ??
Результат void

funcStartHandler() публичный Метод

derives and calls the Start Handler function
public funcStartHandler ( mixed $xp, mixed $elem, mixed $attribs ) : void
$xp mixed ??
$elem mixed ??
$attribs mixed ??
Результат void

parse() публичный Метод

Central parsing function.
public parse ( ) : boolean | PEAR_Error
Результат boolean | PEAR_Error returns true on success, or a PEAR_Error otherwise

parseString() публичный Метод

Parses a string.
См. также: _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
Результат boolean | PEAR_Error true on success or a PEAR Error

raiseError() публичный Метод

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
Результат XML_Parser_Error reference to the error object

reset() публичный Метод

This allows you to use one parser instance to parse multiple XML documents.
public reset ( ) : boolean | object
Результат boolean | object true on success, PEAR_Error otherwise

setHandlerObj() публичный Метод

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
Результат boolean will always return true

setInput() публичный Метод

You should use setInputFile() or setInputString() if you pass a string
См. также: parse()
public setInput ( mixed $fp ) : mixed
$fp mixed Can be either a resource returned from fopen(), a URL, a local filename or a string.
Результат mixed

setInputFile() публичный Метод

Sets the input xml file to be parsed
public setInputFile ( string $file ) : resource
$file string Filename (full path)
Результат resource fopen handle of the given file

setInputString() публичный Метод

Sets the xml input from a string
public setInputString ( string $data ) : null
$data string a string containing the XML document
Результат null

setMode() публичный Метод

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'
Результат boolean | object true on success, PEAR_Error otherwise

startHandler() публичный Метод

abstract method signature for Start Handler
public startHandler ( mixed $xp, mixed $elem, &$attribs ) : null
$xp mixed ??
$elem mixed ??
Результат null

Описание свойств

$_handlerObj публичное свойство

handler object
public object $_handlerObj
Результат object

$_validEncodings публичное свойство

valid encodings
public array $_validEncodings
Результат array

$folding публичное свойство

If set to true, all tag and attribute names will be converted to UPPER CASE.
public bool $folding
Результат boolean

$fp публичное свойство

File handle if parsing from a file
public resource $fp
Результат resource

$handler публичное свойство

Mapping from expat handler function to class method.
public array $handler
Результат array

$mode публичное свойство

Mode of operation, one of "event" or "func"
public string $mode
Результат string

$parser публичное свойство

XML parser handle
См. также: xml_parser_create()
public resource $parser
Результат resource

$srcenc публичное свойство

source encoding
public string $srcenc
Результат string

$tgtenc публичное свойство

target encoding
public string $tgtenc
Результат string