function parseXML($source) { // Clear any content that this object might have // Call: $this->removeNode() // Get xml declration from document and set in object if (preg_match("/<?xml\\ (.*?)\\?>/i", $source, $matches)) { $this->xmlDecl = "<?xml " . $matches[1] . "?>"; // Get version if (preg_match("/version=\"(.*?)\"/i", $matches[1], $versionInfo)) { $this->version = $versionInfo[1]; } // Get encoding if (preg_match("/encoding=\"(.*?)\"/i", $matches[1], $encodingInfo)) { $this->encoding = $encodingInfo[1]; } } // Get document type decleration from document and set in object if (preg_match("/<!doctype\\ (.*?)>/i", $source, $matches)) { $this->docTypeDecl = "<!DOCTYPE " . $matches[1] . ">"; } // Strip white space between tags - not _in_ tags $source = preg_replace("/>\\s+</i", "><", $source); $source = preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/", '', $source); // Parse the xml document to an array structure //$parser = xml_parser_create($this->encoding); $parser = xml_parser_create('ISO-8859-1'); //$parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); $ret = xml_parse_into_struct($parser, $source, $vals); xml_parser_free($parser); // parse the structure and create this object... if (!empty($vals)) { $root = XMLNode::createElement($vals[0]['tag']); $root->attributes = isset($vals[0]['attributes']) ? $vals[0]['attributes'] : NULL; $root->childNodes = $root->_xml_get_children($vals, $i = 0); $this->appendChild($root); } return $ret; }