note 51343 deleted from ref.xml by nlopess
| From: | nlopess@php.net | Date: | Thu, 15 Feb 2007 15:22:27 +0000 |
| Subject: | note 51343 deleted from ref.xml by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123453@lists.php.net to get a copy of this message | ||
Note Submitter: kerxen at caramail dot com
----
To use XML with objetcs, we can use xml_set_object () :
Pour utiliser XML avec des objets, on utilise xml_set_object () :
class xml {
var $parser;
function xml() // constructor
{
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
xml_set_character_data_handler($this->parser, "cdata");
}
function tag_open($parser, $tag, $attributes)
{
var_dump($parser, $tag, $attributes);
}
function tag_close($parser, $tag)
{
var_dump($parser, $tag);
}
function cdata($parser, $cdata)
{
var_dump($parser, $cdata);
}
function parse($data)
{
xml_parse($this->parser, $data);
}
} // end of class xml
$xml_parser = new xml(); // creation of the objet
$xml_parser->parse("<a id='hello World'>PHP</a>");
Have a nice use of this piece of code.
This can be used to share XML files with others sites.
Eddy
http://www.djfrance.net