getName();
if($ns)$tagName=$ns.':'.$tagName;
$array=array();
$array[$tagName]['@attributes']=self::getAttributes($xml,$rootXML);
if(self::hasChildren($xml,$rootXML)){
$children=self::getChildren($xml,$rootXML);
echo ''.$tagName.'
'.print_r($children,true).''; foreach($children as $fullChildName=>$childCollection){ //$child=$childCollection; $childName=split(':',$fullChildName); foreach($childCollection as $child){ $childParsed=self::parsetag($child,$childName[0],$rootXML); //$cIndex=count($array[$tagName][$childName]); $array[$tagName][]=$childParsed; } } }else{ $array[$tagName]['value']=(string)$xml; } return $array; } private static function hasChildren($xml,$rootXML){ return count(self::getChildren($xml,$rootXML))>0; } private static function getAttributes($xml,$rootXML){ $attr=array(); $namespaces=$rootXML->getNamespaces(true); foreach($namespaces as $namespace=>$uri){ $nsAttrs=(array)$xml->attributes($uri); $nsAttrs=isset($nsAttrs['@attributes'])?$nsAttrs['@attributes']:array(); foreach($nsAttrs as $nsAttr=>$nsAttrVal){ //TODO: Support for multiple same name tags $attr[$namespace.':'.$nsAttr]=$nsAttrVal; } } return $attr; } private static function getChildren($xml,$rootXML){ $children=array(); $namespaces=$rootXML->getNamespaces(true); foreach($namespaces as $namespace=>$uri){ $nsChildren=$xml->children($uri); foreach($nsChildren as $nsChild){ //TODO: Support for multiple same name tags $childRealName=$namespace.':'.$nsChild->getName(); if(!isset($children[$childRealName]))$children[$childRealName]=array(); if(!is_array($children[$childRealName]))$children[$childRealName]=array(); $children[$childRealName][]=$nsChild; } } return $children; } } $xml='
'.htmlentities($xml).''; //echo '
'.print_r($struct,true).''; //echo '
'.print_r($sxml,true).''; //cho '
'.print_r(xml2array($xml),true).''; echo '
'.print_r(xml2array::parse($xml),true).''; //echo http_get_request_headers(); ?>