/', $val)) { throw new InvalidArgumentException('XML Doctype parsing disabled'); } // Disable external entity loading if($disableExternals) $oldVal = libxml_disable_entity_loader($disableExternals); try { $xml = new SimpleXMLElement($val); $result = self::recursiveXMLToArray($xml); } catch(Exception $ex) { if($disableExternals) libxml_disable_entity_loader($oldVal); throw $ex; } if($disableExternals) libxml_disable_entity_loader($oldVal); return $result; } /** * Convert a XML string to a PHP array recursively. Do not * call this function directly, Please use {@link Convert::xml2array()} * * @param SimpleXMLElement * * @return mixed */ protected static function recursiveXMLToArray($xml) { if(is_object($xml) && get_class($xml) == 'SimpleXMLElement') { $attributes = $xml->attributes(); foreach($attributes as $k => $v) { if($v) $a[$k] = (string) $v; } $x = $xml; $xml = get_object_vars($xml); } if(is_array($xml)) { if(count($xml) == 0) return (string) $x; // for CDATA foreach($xml as $key => $value) { $r[$key] = self::recursiveXMLToArray($value); } if(isset($a)) $r['@'] = $a; // Attributes return $r; } return (string) $xml; } }