/* Here are the XML functions needed by expat * *
/* When expat hits a opening tag, it fires up this function * *
function startelement ($parser, $name, $attrs) {
Array_push ($this->current_tag, $name); Add tag to the cur. Tag array
$curtag = Implode ("_", $this->current_tag); Piece together Tag
/* This tracks what array index we are in for this tag */
if (Isset ($this->tagtracker["$curtag"])) {
$this->tagtracker["$curtag"]++;
} else {
$this->tagtracker["$curtag"]=0;
}
/* If there are attributes for this tag, we have set them here. */
if (count ($attrs) >0) {
$j = $this->tagtracker["$curtag"];
if (! $j) $j = 0;
if (!is_object ($GLOBALS [$this->identifier]["$curtag"] [$j])) {
$GLOBALS [$this->identifier]["$curtag"] [$j] = new Xml_container;
}
$GLOBALS [$this->identifier]["$curtag"] [$j]->store ("Attributes", $attrs);
}
}//End Function startelement
/* When expat hits a closing tag, it fires the up this function * *
function EndElement ($parser, $name) {
$curtag = Implode ("_", $this->current_tag); Piece together Tag
Before we pop it off,
So we can get the correct
Cdata
if (! $this->tagdata["$curtag"]) {
$popped = Array_pop ($this->current_tag); Or else we screw up where we are
Return If we have no data for the tag
} else {
$TD = $this->tagdata["$curtag"];
unset ($this->tagdata["$curtag");
}
$popped = Array_pop ($this->current_tag);
We want the tag name for
The tag above this, it
Allows us to group the
Tags together in a
Intuitive Way.
if (sizeof ($this->current_tag) = = 0) return; If we aren ' t in a tag
$curtag = Implode ("_", $this->current_tag); Piece together Tag
This time is for the arrays
$j = $this->tagtracker["$curtag"];
if (! $j) $j = 0;
if (!is_object ($GLOBALS [$this->identifier]["$curtag"] [$j])) {
$GLOBALS [$this->identifier]["$curtag"] [$j] = new Xml_container;
}
$GLOBALS [$this->identifier]["$curtag"] [$j]->store ($name, $TD); # $this->tagdata["$curtag"]);
Unset ($TD);
return TRUE;
}
/* When Expat finds some internal tag character data,
It fires up this function * *
function Characterdata ($parser, $cdata) {
$curtag = Implode ("_", $this->current_tag); Piece together Tag
$this->tagdata["$curtag"]. = $cdata;
}
/* This is the constructor:automatically called then the class is initialized * *
function XML ($data, $identifier = ' xml ') {
$this->identifier = $identifier;
Create parser Object
$this->xml_parser = Xml_parser_create ();
Set up some options and handlers
Xml_set_object ($this->xml_parser, $this);
Xml_parser_set_option ($this->xml_parser,xml_option_case_folding,0);
Xml_set_element_handler ($this->xml_parser, "startelement", "endelement");
Xml_set_character_data_handler ($this->xml_parser, "Characterdata");
if (!xml_parse ($this->xml_parser, $data, TRUE)) {
sprintf ("XML error:%s at line%d")
Xml_error_string (Xml_get_error_code ($this->xml_parser)),
Xml_get_current_line_number ($this->xml_parser));
}
We are done with the parser
Xml_parser_free ($this->xml_parser);
}//End constructor:function XML ()
}//Thus, we end class XML
?>