Set($xml_content); echo( "
\n" );
print_r($XML->obj_data);
echo( "
\n" ); class Xml { var $xmlAll; var $obj_data; var $pos; function Xml() { // ------------- /// PHP 5 uses __construct. // To make this work with PHP4+ // and PHP5 make the function the same name // as the class. // -------------- } // ------------- // wsFunc is a function to find the current position // after stripping out the whitespace // requires two arguements // returns the position // ------------- function _wsFunc($parser, $data) { if(trim($data)) { $this->pos[$this->index] = trim($data); } } // ------------- // Whitespaces... Evil // make sure we clean thse out // trim the string, then decode it // urgh..thats about it! // ------------- function _cleanString($string) { return utf8_decode(trim($string)); } // ------------- // Probabally the most important function // sets the data and then runs the main XML functions // The pointer plays a vital part in this. // ------------- function Set(&$xmlAll) { $this->index = 0; $this->pos[] = &$this->obj_data; $this->xmlAll = $xmlAll; // ------------- // UTF-8 is the right character encoding // Change this on the fly. // check for more character encodings. // php.net/xml_parser_create // ------------- $this->xml_parser = xml_parser_create("UTF-8"); // ------------- // Set the options for this function // Need to set XML_OPTION to false // ------------- xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false); // ------------- // Set the object // Will allow the class // ------------- xml_set_object($this->xml_parser,&$this); // ------------- // Set the element handles to functions // _startHandle is a function // _endHandle is a function // ------------- xml_set_element_handler($this->xml_parser,"_startHandle", "_endHandle"); // ------------- // Removing white spaces.. // make sure no white spaces on the tags // This needs to be run on the data handler. // ------------- xml_set_character_data_handler($this->xml_parser, "_wsFunc"); // ------------- // Parse on the fly. // Options available true|false // ------------- xml_parse($this->xml_parser, $this->xmlAll, true); // ------------- // Free the XML data // Very important to CALL this // ------------- xml_parser_free($this->xml_parser); } // ------------- // Damnit, i dont like using eval() // However, this was the only way i could see through it // I need to find a better way eventually // well, atleast before this is ready for release. // requires three vars. // returns the eval results. // ------------- function _startHandle($parser, $tag, $attributeList) { foreach($attributeList as $name => $value) { $value = $this->_cleanString($value); $object->$name = $value; } eval("\$this->pos[\$this->index]->" . $tag . "[] = \$object;"); eval("\$size = sizeof( \$this->pos[\$this->index]->" . $tag . " );"); eval("\$this->pos[] = &\$this->pos[\$this->index]->" . $tag . "[\$size-1];"); $this->index++; } // ------------- // Used like _startHandle // very simply for xml_set_element_handler() // pop le' array // ------------- function _endHandle($parser, $tag) { array_pop($this->pos); $this->index--; } } ?>