<?php
error_reporting(E_ALL);
class XML {
var $parser; #a reference to the XML parser
var $document; #the entire XML structure built up so far
var $current; #a pointer to the current item - what is this
var $parent; #a pointer to the current parent - the parent will be an array
var $parents; #an array of the most recent parent at each level
var $last_opened_tag;
function XML($data=null){
$this->parser = xml_parser_create();
xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, "open", "close");
xml_set_character_data_handler($this->parser, "data");
# register_shutdown_function(array(&$this, 'destruct'));
}
function destruct(){
xml_parser_free($this->parser);
}
function parse($data){
$this->document = array();
$this->parent = &$this->document;
$this->parents = array();
$this->last_opened_tag = NULL;
xml_parse($this->parser, $data);
return $this->document;
}
function open($parser, $tag, $attributes){
#echo "Opening tag $tag<br>\n";
$this->data = "";
$this->last_opened_tag = $tag; #tag is a string
if(array_key_exists($tag, $this->parent)){
#echo "There's already an instance of '$tag' at the current level ($level)<br>\n";
if(is_array($this->parent[$tag]) and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric
#need to make sure they're numeric (account for attributes)
$key = count_numeric_items($this->parent[$tag]);
#echo "There are $key instances: the keys are numeric.<br>\n";
}else{
#echo "There is only one instance. Shifting everything around<br>\n";
$temp = &$this->parent[$tag];
unset($this->parent[$tag]);
$this->parent[$tag][0] = &$temp;
if(array_key_exists("$tag attr", $this->parent)){
#shift the attributes around too if they exist
$temp = &$this->parent["$tag attr"];
unset($this->parent["$tag attr"]);
$this->parent[$tag]["0 attr"] = &$temp;
}
$key = 1;
}
$this->parent = &$this->parent[$tag];
}else{
$key = $tag;
}
if($attributes){
$this->parent["$key attr"] = $attributes;
}
$this->parent[$key] = array();
$this->parent = &$this->parent[$key];
$x = &$this->parent;
array_unshift($this->parents, $x);
}
function data($parser, $data){
#echo "Data is '", htmlspecialchars($data), "'<br>\n";
if($this->last_opened_tag != NULL){
$this->data .= $data;
}
}
function close($parser, $tag){
#echo "Close tag $tag<br>\n";
if($this->last_opened_tag == $tag){
$this->parent = $this->data;
$this->last_opened_tag = NULL;
}
array_shift($this->parents);
$this->parent = &$this->parents[0];
}
}
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; XML has a deprecated constructor in /in/vli9r on line 3
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/vli9r on line 4
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/vli9r on line 5
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/vli9r on line 6
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/vli9r on line 7
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/vli9r on line 8
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/vli9r on line 10