static public function decodeElement($str, $hasRoot=true)
    {
        if (is_array($str)) {
            return $str;
        }
        
        if (!$hasRoot && strpos($str, '<?xml') !== 0 && strpos($str, '<xml') !== 0) {
            $str = "<?xml version='1.0' encoding='utf-8'?><xml>" . $str . "</xml>";
        }
        
        // 禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        // 将xml转为array
        return json_decode(json_encode(simplexml_load_string($str, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
    }
static public function decodeElement($str, $hasRoot=true)
    {
        if (is_array($str)) {
            return $str;
        }
        
        if (!$hasRoot && strpos($str, '<?xml') !== 0 && strpos($str, '<xml') !== 0) {
            $str = "<?xml version='1.0' encoding='utf-8'?><xml>" . $str . "</xml>";
        }
        
        // 禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        // 将xml转为array
        return json_decode(json_encode(simplexml_load_string($str, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
    }
static public function decodeElement ( $ str , $ hasRoot = true ) { if ( is_array ( $ str ) ) { return $ str ; } if ( ! $ hasRoot && strpos ( $ str , '<?xml' ) !== 0 && strpos ( $ str , '<xml' ) !== 0 ) { $ str = "<?xml version='1.0' encoding='utf-8'?><xml>" . $ str . "</xml>" ; } // 禁止引用外部xml实体 libxml_disable_entity_loader ( true ) ; // 将xml转为array return json_decode ( json_encode ( simplexml_load_string ( $ str , 'SimpleXMLElement' , LIBXML_NOCDATA ) ) , true ) ; }
from xml string to array, use single entity parse
@param  string  $str
@param  boolean $hasRoot str is contain root element
@return array
from xml string to array use single entity parse