Какова лучшая функция php DOM 2 Array?

Я хочу проанализировать XML-файлы. Лучший способ, который я нашел, - это до сих пор использовать класс DOMDocument ().

Пример строки XML:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<response>
<resData>
<contact:infData xmlns:contact="http://example.com/contact-1.0">
<contact:status s="value1"/>
<contact:status s="value2"/>
<contact:status s="value3"/>
<contact:status s="value4"/>
</contact:infData>
</resData>
</response>

Я использую функцию dom2array (ниже) для анализа dom, но она возвращает только 1 элемент (только value4)

<?php
    function dom2array($node) {
    $res = array();
    if($node->nodeType == XML_TEXT_NODE){
       $res = $node->nodeValue;
    }else{
       if($node->hasAttributes()){
           $attributes = $node->attributes;
            if(!is_null($attributes)){
               $res['@attributes'] = array();
               foreach ($attributes as $index=>$attr) {
                   $res['@attributes'][$attr->name] = $attr->value;
               }
           }
       }
       if($node->hasChildNodes()){
           $children = $node->childNodes;
           for($i=0;$i<$children->length;$i++){
               $child = $children->item($i);
               $res[$child->nodeName] = dom2array($child);
           }
       }
    }
    return $res;
    }
?>

Есть ли способ проанализировать все элементы XML и отправить их в массив?

выходной массив:

Array
(
[response] => Array
    (
        [#text] => 

        [resData] => Array
            (
                [#text] => 

                [contact:infData] => Array
                    (
                        [#text] => 

                        [contact:status] => Array
                            (
                                [@attributes] => Array
                                    (
                                        [s] => value4
                                    )

                            )

                    )

            )

    )

)

Где значение1, значение2, значение3? :( Спасибо

Ответы на вопрос(1)

Ваш ответ на вопрос