[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/XML/Parser/ -> Simple.php (sommaire)

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.

Author: Stephan Schmidt <schst@php-tools.net>
Poids: 297 lignes (9 kb)
Inclus ou requis: 3 fois
Référencé: 0 fois
Nécessite: 1 fichier
 XML/Parser.php

Définit 1 class

XML_Parser_Simple:: (9 méthodes):
  XML_Parser_Simple()
  _initHandlers()
  reset()
  startHandler()
  endHandler()
  cdataHandler()
  handleElement()
  getCurrentDepth()
  addToData()


Classe: XML_Parser_Simple  - X-Ref

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.

<code>
require_once '../Parser/Simple.php';

class myParser extends XML_Parser_Simple
{
function myParser()
{
$this->XML_Parser_Simple();
}

function handleElement($name, $attribs, $data)
{
printf('handle %s<br>', $name);
}
}

$p = &new myParser();

$result = $p->setInputFile('myDoc.xml');
$result = $p->parse();
</code>

XML_Parser_Simple($srcenc = null, $mode = 'event', $tgtenc = null)   X-Ref
Creates an XML parser.

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

param: string $srcenc source charset encoding, use NULL (default) to use
param: string $mode   how this parser object should work, "event" for
param: string $tgenc  a valid target encoding

_initHandlers()   X-Ref
inits the handlers


reset()   X-Ref
Reset the parser.

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

return: boolean|object     true on success, PEAR_Error otherwise

startHandler($xp, $elem, &$attribs)   X-Ref
start handler

Pushes attributes and tagname onto a stack

param: resource    xml parser resource
param: string      element name
param: array       attributes

endHandler($xp, $elem)   X-Ref
end handler

Pulls attributes and tagname from a stack

param: resource    xml parser resource
param: string      element name

cdataHandler($xp, $data)   X-Ref
handle character data

param: resource    xml parser resource
param: string      data

handleElement($name, $attribs, $data)   X-Ref
handle a tag

Implement this in your parser

param: string      element name
param: array       attributes
param: string      character data

getCurrentDepth()   X-Ref
get the current tag depth

The root tag is in depth 0.

return: integer

addToData( $data )   X-Ref
add some string to the current ddata.

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

param: string      data to add
return: void



Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7