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

Class: XML_Parser

Source Location: /XML_Parser-1.1.0/Parser.php

Class Overview

PEAR
   |
   --XML_Parser

XML Parser class.


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 99]
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: create XML_Parser_Pull
  • 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_Simple, that automatically builds a stack and passes name, attributes and cdata to the end element handler


[ Top ]


Class Variables

$folding =  true

[line 126]

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 116]

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 140]

Mapping from expat handler function to class method.

Type:   array


[ Top ]

$mode =

[line 133]

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

Type:   string


[ Top ]

$parser =

[line 109]

XML parser handle

Type:   resource


[ Top ]

$srcenc =

[line 154]

source encoding

Type:   string


[ Top ]

$tgtenc =

[line 161]

target encoding

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 195]

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 179]

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 565]

void endHandler( $xp, $elem)

  • Abstract:

Parameters:

   $xp   — 
   $elem   — 

[ Top ]

free   [line 494]

null free( )

XML_Parser::free()

Free the internal resources associated with the parser


[ Top ]

funcEndHandler   [line 538]

void funcEndHandler( $xp, $elem)


Parameters:

   $xp   — 
   $elem   — 

[ Top ]

funcStartHandler   [line 527]

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


Parameters:

   $xp   — 
   $elem   — 
   $attribs   — 

[ Top ]

parse   [line 414]

true|object PEAR parse( )

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

[ Top ]

parseString   [line 471]

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 516]

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

XML_Parser::raiseError()

Trows a XML_Parser_Error and free's the internal resources


Parameters:

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

[ Top ]

reset   [line 309]

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

[ Top ]

setInput   [line 382]

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 329]

resource setInputFile( string $file)

Sets the input xml file to be parsed

Parameters:

string   $file   —  Filename (full path)

[ Top ]

setInputString   [line 361]

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 225]

void setMode( string $mode)

Sets the mode of the parser.

Possible modes are:

  • func
  • event
This also sets all handlers for the parser.

You do not need to call this method in most cases, as it's called automatically when parsing a document.

You can set the mode using the second parameter in the constructor.


Parameters:

string   $mode   — 

[ Top ]

startHandler   [line 553]

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

  • Abstract:

Parameters:

   $xp   — 
   $elem   — 
   &$attribs   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 10:15:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.