(PHP 4, PHP 5, PHP 7)
xml_set_object — 锟节讹拷锟斤拷锟斤拷使锟斤拷 XML 锟斤拷锟斤拷锟斤拷
锟矫猴拷锟斤拷使锟斤拷 parser
指锟斤拷锟侥斤拷锟斤拷锟斤拷锟斤拷锟皆憋拷锟斤拷锟斤拷 object
锟斤拷锟斤拷锟叫★拷锟斤拷锟叫的回叫猴拷锟斤拷锟斤拷callback function锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 xml_set_element_handler() 锟饺猴拷锟斤拷锟斤拷锟斤拷锟矫o拷锟斤拷锟角憋拷锟劫讹拷为 object
锟斤拷锟斤拷姆锟斤拷锟斤拷锟�
Example #1 xml_set_object() 示锟斤拷
<?php
class xml {
var $parser;
function xml()
{
$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 parse($data)
{
xml_parse($this->parser, $data);
}
function tag_open($parser, $tag, $attributes)
{
var_dump($parser, $tag, $attributes);
}
function cdata($parser, $cdata)
{
var_dump($parser, $cdata);
}
function tag_close($parser, $tag)
{
var_dump($parser, $tag);
}
} // end of class xml
$xml_parser = new xml();
$xml_parser->parse("<A ID='hallo'>PHP</A>");
?>