XML_Parser
[ class tree: XML_Parser ] [ index: XML_Parser ] [ all elements ]

Class: XML_Parser

Source Location: /XML_Parser-1.2.3/Parser.php

Class Overview

PEAR
   |
   --XML_Parser

XML Parser class.


Author(s):

Variables

Methods


Child classes:

myParser
XML Parser class.
XML_Parser_Simple
Simple XML parser class.

Inherited Variables

Inherited Methods


Class Details

[line 96]
XML Parser class.

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 <name></name> tags of your xml file.

  • Author: Stephan Schmidt <schst@php-tools.net>
  • Author: Stig Bakken <ssb@fast.no>
  • Author: Tomas V.V.Cox <cox@idecnet.com>
  • Todo: create XML_Parser_Namespace to parse documents with namespaces
  • Todo: Tests that need to be made:
    • mixing character encodings
    • a test using all expat handlers
    • options (folding, output charset)
    • different parsing modes
  • Todo: create XML_Parser_Pull


[ Top ]


Class Variables

$folding =  true

[line 123]

Whether to do case folding

If set to true, all tag and attribute names will be converted to UPPER CASE.


Type:   boolean


[ Top ]

$fp =

[line 113]

File handle if parsing from a file

Type:   resource


[ Top ]

$handler = array(
        'character_data_handler'            => 'cdataHandler',
        'default_handler'                   => 'defaultHandler',
        'processing_instruction_handler'    => 'piHandler',
        'unparsed_entity_decl_handler'      => 'unparsedHandler',
        'notation_decl_handler'             => 'notationHandler',
        'external_entity_ref_handler'       => 'entityrefHandler'
    )

[line 137]

Mapping from expat handler function to class method.

Type:   array


[ Top ]

$mode =

[line 130]

Mode of operation, one of "event" or "func"

Type:   string


[ Top ]

$parser =

[line 106]

XML parser handle

Type:   resource


[ Top ]

$srcenc =

[line 151]

source encoding

Type:   string


[ Top ]

$tgtenc =

[line 158]

target encoding

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 199]

XML_Parser __construct( [string $srcenc = null], [string $mode = 'event'], [ $tgtenc = null], string $tgenc)

PHP5 constructor

Parameters:

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

[ Top ]

XML_Parser (Constructor)   [line 183]

XML_Parser XML_Parser( [string $srcenc = null], [string $mode = 'event'], [ $tgtenc = null], string $tgenc)

Creates an XML parser.

This is needed for PHP4 compatibility, it will call the constructor, when a new instance is created.


Parameters:

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

[ Top ]

endHandler   [line 621]

void endHandler( $xp, $elem)

  • Abstract:

Parameters:

   $xp   — 
   $elem   — 

[ Top ]

free   [line 547]

null free( )

XML_Parser::free()

Free the internal resources associated with the parser


[ Top ]

funcEndHandler   [line 592]

void funcEndHandler( $xp, $elem)


Parameters:

   $xp   — 
   $elem   — 

[ Top ]

funcStartHandler   [line 579]

void funcStartHandler( $xp, $elem, $attribs)


Parameters:

   $xp   — 
   $elem   — 
   $attribs   — 

[ Top ]

parse   [line 462]

true|object PEAR parse( )

Central parsing function.
  • Return: error returns true on success, or a PEAR_Error otherwise
  • Access: public

[ Top ]

parseString   [line 522]

Pear parseString( string $data, [boolean $eof = false])

XML_Parser::parseString()

Parses a string.

  • Return: Error|true true on success or a PEAR Error
  • See: _parseString()
  • Throws: XML_Parser_Error

Parameters:

string   $data   —  XML data
boolean   $eof   —  If set and TRUE, data is the last piece of data sent in this parser

[ Top ]

raiseError   [line 569]

XML_Parser_Error raiseError( [string $msg = null], [integer $ecode = 0])

XML_Parser::raiseError()

Throws a XML_Parser_Error


Parameters:

string   $msg   —  the error message
integer   $ecode   —  the error message code

[ Top ]

reset   [line 353]

boolean|object reset( )

Reset the parser.

This allows you to use one parser instance to parse multiple XML documents.

  • Return: true on success, PEAR_Error otherwise
  • Access: public

Overridden in child classes as:

XML_Parser_Simple::reset()
Reset the parser.

[ Top ]

setHandlerObj   [line 251]

boolean setHandlerObj( object object &$obj)

Sets the object, that will handle the XML events

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.

  • Return: will always return true
  • Since: v1.2.0beta3
  • Access: public

Parameters:

object object   &$obj   —  to handle the events

[ Top ]

setInput   [line 430]

void setInput( mixed $fp)

Sets the file handle to use with parse().

You should use setInputFile() or setInputString() if you pass a string


Parameters:

mixed   $fp   —  Can be either a resource returned from fopen(), a URL, a local filename or a string.

[ Top ]

setInputFile   [line 373]

resource setInputFile( string $file)

Sets the input xml file to be parsed

Parameters:

string   $file   —  Filename (full path)

[ Top ]

setInputString   [line 409]

null setInputString( string $data)

XML_Parser::setInputString()

Sets the xml input from a string


Parameters:

string   $data   —  a string containing the XML document

[ Top ]

setMode   [line 226]

boolean|object setMode( string $mode)

Sets the mode of the parser.

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.

  • Return: true on success, PEAR_Error otherwise
  • Access: public

Parameters:

string   $mode   —  mode, either 'func' or 'event'

[ Top ]

startHandler   [line 609]

void startHandler( $xp, $elem, &$attribs)

  • Abstract:

Parameters:

   $xp   — 
   $elem   — 
   &$attribs   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:13:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.