예제 #1
0
 /**
  * Parse an XML document into an array. Supports namespaces. Uses SimpleXML
  *
  * @param String/SimpleXMLElement $xml
  * @return Array
  */
 public static function parse($xml)
 {
     $xml = get_class($xml) == 'SimpleXMLElement' ? $xml : @simplexml_load_string($xml);
     if (get_class($xml) != 'SimpleXMLElement') {
         die('The string passed is not a valid XML string or an SimpleXMLElement');
     }
     self::$namespaces = $xml->getNamespaces(true);
     return self::parsetag($xml);
 }
예제 #2
0
 protected function xml2array($xml)
 {
     if (trim($xml) == '') {
         return array();
     }
     if (class_exists('XMLns2array')) {
         $array = XMLns2array::parse($xml);
     } else {
         $array = json_decode(json_encode(@simplexml_load_string($xml)), true);
     }
     return $array;
 }