我该如何分离这些xml元素?

时间:2014-03-25 01:23:41

标签: php xml simplexml

我得到了

的xml响应
SimpleXMLElement Object
    (
    [@attributes] => Array
        (
            [version] => 2.0
            [msg_type] => response
        )

    [header] => SimpleXMLElement Object
        (
            [param] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [name] => SN
                                    [value] => 1012
                                )

                        )


    ...

                    [9] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [name] => ErrorInfo
                                    [value] => NA
                                )

                        )

                    [10] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [name] => ProcessTime
                                    [value] => 0
                                )

                        )

                )

        )

    [Heartbeat] => SimpleXMLElement Object
        (
        )

)

我试过了:

$version1 = (string) $xml->version; // expecting to get "2.0"
$errorinfo = (string) $xml->name->ErrorInfo; // expecting to get "NA"

0 个答案:

没有答案