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=' Main Repository 0f91f397-7cd1-479b-9f56-266affe188d8 Main Repository self Alfresco Alfresco Repository (Labs) 3.0.0 (Stable 1526) http://localhost:8080/alfresco/service/api/path/workspace/SpacesStore/Company%20Home true false false true true false both nojoin fulltextandstructured 0.5 root collection root collection checkedout collection unfiled collection type collection type collection query collection '; $sxml=simplexml_load_string($xml); $struct=json_decode(json_encode($sxml),true); echo '
'.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(); ?>