Class XML_Parser_Simple

Description

Simple XML parser class.

This class is a simplified version of XML_Parser. In most XML applications the real action is executed, when a closing tag is found.

XML_Parser_Simple allows you to just implement one callback for each tag that will receive the tag with its attributes and CData.

  1. require_once '../Parser/Simple.php';
  2.  
  3. class myParser extends XML_Parser_Simple
  4. {
  5. function myParser()
  6. {
  7. $this->XML_Parser_Simple();
  8. }
  9.  
  10. function handleElement($name, $attribs, $data)
  11. {
  12. printf('handle %s<br>', $name);
  13. }
  14. }
  15.  
  16. $p = &new myParser();
  17.  
  18. $result = $p->setInputFile('myDoc.xml');
  19. $result = $p->parse();

  • copyright: 1997-2006 The PHP Group
  • version: Release: 1.4.9
  • author: Stephan Schmidt <schst@php-tools.net>

Located in /PEAR/XML/Parser/Simple.php (line 79)

PEAR
   |
   --XML_Parser
      |
      --XML_Parser_Simple
Variable Summary
 array $handler
Method Summary
 XML_Parser_Simple XML_Parser_Simple ([string $srcenc = null], [string $mode = 'event'], [mixed $tgtenc = null], string $tgenc)
 void addToData (string $data)
 integer getCurrentDepth ()
 void handleElement (string $name, array $attribs, string $data)
 boolean|object reset ()
Variables
array $handler = array(
'default_handler' => 'defaultHandler',
'processing_instruction_handler' => 'piHandler',
'unparsed_entity_decl_handler' => 'unparsedHandler',
'notation_decl_handler' => 'notationHandler',
'external_entity_ref_handler' => 'entityrefHandler'
)
(line 110)

Mapping from expat handler function to class method.


Redefinition of:
XML_Parser::$handler
Mapping from expat handler function to class method.

Inherited Variables

Inherited from XML_Parser

XML_Parser::$folding
XML_Parser::$fp
XML_Parser::$mode
XML_Parser::$parser
XML_Parser::$srcenc
XML_Parser::$tgtenc
XML_Parser::$_handlerObj
Methods
Constructor XML_Parser_Simple (line 131)

Creates an XML parser.

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

XML_Parser_Simple XML_Parser_Simple ([string $srcenc = null], [string $mode = 'event'], [mixed $tgtenc = null], string $tgenc)
  • string $srcenc: source charset encoding, use NULL (default) to use whatever the document specifies
  • string $mode: how this parser object should work, "event" for handleElement(), "func" to have it call functions named after elements (handleElement_$name())
  • string $tgenc: a valid target encoding
addToData (line 292)

add some string to the current ddata.

This is commonly needed, when a document is parsed recursively.

  • access: public
void addToData (string $data)
  • string $data: data to add
getCurrentDepth (line 278)

get the current tag depth

The root tag is in depth 0.

  • access: public
integer getCurrentDepth ()
handleElement (line 266)

handle a tag

Implement this in your parser

  • abstract:
  • access: public
void handleElement (string $name, array $attribs, string $data)
  • string $name: element name
  • array $attribs: attributes
  • string $data: character data
reset (line 175)

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
boolean|object reset ()

Redefinition of:
XML_Parser::reset()
Reset the parser.

Inherited Methods

Inherited From XML_Parser

 XML_Parser::XML_Parser()
 XML_Parser::__construct()
 XML_Parser::endHandler()
 XML_Parser::free()
 XML_Parser::funcEndHandler()
 XML_Parser::funcStartHandler()
 XML_Parser::parse()
 XML_Parser::parseString()
 XML_Parser::raiseError()
 XML_Parser::reset()
 XML_Parser::setHandlerObj()
 XML_Parser::setInput()
 XML_Parser::setInputFile()
 XML_Parser::setInputString()
 XML_Parser::setMode()
 XML_Parser::startHandler()

Inherited From PEAR

 PEAR::PEAR()
 PEAR::delExpect()
 PEAR::expectError()
 PEAR::getStaticProperty()
 PEAR::isError()
 PEAR::loadExtension()
 PEAR::popErrorHandling()
 PEAR::popExpect()
 PEAR::pushErrorHandling()
 PEAR::raiseError()
 PEAR::registerShutdownFunc()
 PEAR::setErrorHandling()
 PEAR::staticPopErrorHandling()
 PEAR::staticPushErrorHandling()
 PEAR::throwError()
 PEAR::_PEAR()

Documentation generated on Mon, 04 Dec 2006 11:10:10 -0500 by phpDocumentor 1.3.0RC3