parse($strYourXML);
print_r($arrOutput); //print it out, or do whatever!
*/
class xml2Array {
var $arrOutput = array();
var $resParser;
var $strXmlData;
function parse($strInputXML) {
$this->resParser = xml_parser_create ();
xml_set_object($this->resParser,$this);
xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
xml_set_character_data_handler($this->resParser, "tagData");
$this->strXmlData = xml_parse($this->resParser,$strInputXML );
if(!$this->strXmlData) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->resParser)),
xml_get_current_line_number($this->resParser)));
}
xml_parser_free($this->resParser);
return $this->arrOutput;
}
function tagOpen($parser, $name, $attrs) {
$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($this->arrOutput,$tag);
}
function tagData($parser, $tagData) {
if(trim($tagData)) {
if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) {
$this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $tagData;
}
else {
$this->arrOutput[count($this->arrOutput)-1]['tagData'] = $tagData;
}
}
}
function tagClosed($parser, $name) {
$this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1];
array_pop($this->arrOutput);
}
}
//$url="http://armory.wow-europe.com/character-sheet.xml?r=Terenas&n=Thumann";
function curl_string ($url,$user_agent){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec ($ch);
curl_close($ch);
return $result;
}
$url_page = "http://armory.wow-europe.com/character-sheet.xml?r=Terenas&n=Thumann";
$user_agent = "Mozilla/5.0 Firefox/2.0.0.1";
$xml = curl_string($url_page,$user_agent);
/*$xml= '
';*/
$objXML = new xml2Array();
$arrOutput = $objXML->parse($xml);
print_r($arrOutput); //print it out, or do whatever!
/*$name = $arrOutput[0]['children'][0]['children'][0]['attrs']['NAME'];
$pvp_rank = $arrOutput[0]['children'][0]['children'][0]['attrs']['TITLE'];
$guild = $arrOutput[0]['children'][0]['children'][0]['attrs']['GUILDNAME'];
$level = $arrOutput[0]['children'][0]['children'][0]['attrs']['LEVEL'];
$race = $arrOutput[0]['children'][0]['children'][0]['attrs']['RACE'];
$class = $arrOutput[0]['children'][0]['children'][0]['attrs']['CLASS'];
$realm = $arrOutput[0]['children'][0]['children'][0]['attrs']['REALM'];
$faction = $arrOutput[0]['children'][0]['children'][0]['attrs']['FACTION'];
$gender = $arrOutput[0]['children'][0]['children'][0]['attrs']['GENDER'];
echo $pvp_rank.' '.$name.'
';
echo 'Level '.$level.' '.$race.' '.$class.'
';
echo 'Of '.$guild.', '.$realm.'
';
*/
?>