PHP xml_set_object() 함수
예시
객체 내에서 XML 파서를 사용:
<?php
class XMLParser
{
private $parser;
function
__construct() {
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser,
"start_tag", "end_tag");
xml_set_character_data_handler($this->parser,
"cdata");
}
function __destruct() {
xml_parser_free($this->parser);
unset($this->parser);
}
function parse($data) {
xml_parse($this->parser, $data);
}
function start_tag($parser, $tag, $attributes) {
var_dump($tag,
$attributes);
}
function cdata($parser, $cdata) {
var_dump($cdata);
}
function end_tag($parser, $tag) {
var_dump($tag);
}
}
$xml_parser = new XMLParser();
$xml_parser->parse("<p
id='test'>Hello World!</p>");
?>
정의 및 사용
xml_set_object() 함수를 사용하면 객체 내에서 XML 파서를 사용할 수 있습니다.
통사론
xml_set_object(parser, object)
매개변수 값
Parameter | Description |
---|---|
parser | Required. Specifies the XML parser to use |
object | Required. Specifies the object where to use the XML parser |
기술적 세부 사항
반환 값: | 성공 시 TRUE입니다. 실패시 FALSE |
---|---|
PHP 버전: | 4.0+ |
❮ PHP XML 파서 참조