note 79630 deleted from ref.xml by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Mar 2010 18:56:05 +0000 |
| Subject: | note 79630 deleted from ref.xml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166625@lists.php.net to get a copy of this message | ||
Note Submitter: aquariusrick
----
Here's another attempt at a very simple script that parses XML into a structure:
<?php
#Usage:
//$xml_parser = new xml();
//$xml_parser->parse($xml);
//$dom = $xml_parser->dom;
class xml {
var $parser;
var $pointer;
var $dom;
function xml() {
$this->pointer =& $this->dom;
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
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) {
$this->pointer[$tag] = Array(
'_parent' => &$this->pointer,
'_content' => null,
'_attributes' => $attributes,
);
$this->pointer =& $this->pointer[$tag];
}
function cdata($parser, $cdata) {
$this->pointer['_content'] .= $cdata;
}
function tag_close($parser, $tag) {
$this->pointer =& $this->pointer['_parent'];
unset($this->pointer[$tag]['_parent']);
}
} // end xml class
?>