0

嗨哟,

我经常使用 XML 和 PHP,但我得到的这个特定回报是关于如何在 PHP 中获得它的曲线球。如果我能以某种方式将“$attribute”和“VALUE”转换为 assoc 数组,我会很高兴。

真的很难过和沮丧 - 雷

SimpleXMLElement Object
(
[MULTIPLE] => SimpleXMLElement Object
    (
        [SINGLE] => SimpleXMLElement Object
            (
                [KEY] => Array
                    (
                        [0] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [name] => address
                                    )

                                [VALUE] => SimpleXMLElement Object
                                    (
                                        [@attributes] => Array
                                            (
                                                [null] => null
                                            )

                                    )

                            )

                        [1] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [name] => aim
                                    )

                                [VALUE] => SimpleXMLElement Object
                                    (
                                        [@attributes] => Array
                                            (
                                                [null] => null
                                            )

                                    )

                            )

                        [2] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [name] => auth
                                    )

                                [VALUE] => SimpleXMLElement Object
                                    (
                                        [@attributes] => Array
                                            (
                                                [null] => null
                                            )

                                    )

                            )

更新:这是 XML 输出:

<?xml version="1.0" encoding="UTF-8" ?>
<RESPONSE>
<MULTIPLE>
<SINGLE>
<KEY name="address"><VALUE null="null"/>
</KEY>
<KEY name="aim"><VALUE null="null"/>
</KEY>
<KEY name="auth"><VALUE null="null"/>
</KEY>
<KEY name="city"><VALUE null="null"/>
</KEY>
<KEY name="confirmed"><VALUE null="null"/>
</KEY>
<KEY name="country"><VALUE null="null"/>
</KEY>
<KEY name="deleted"><VALUE null="null"/>
</KEY>
<KEY name="department"><VALUE null="null"/>
</KEY>
<KEY name="description"><VALUE null="null"/>
</KEY>
<KEY name="email"><VALUE null="null"/>
</KEY>
<KEY name="emailstop"><VALUE null="null"/>
</KEY>
<KEY name="error"><VALUE>no match found for idnumber = 301942</VALUE>
</KEY>
<KEY name="firstname"><VALUE null="null"/>
...

我知道如何在以该教程中描述的方式形成 XML 时对其进行解析。但是这个特定的案例让我很难过如何访问我需要的节点(通过 SimpleXML 对象或将其转换为 PHP 数组而不通过这样的节点:

$xml_obj->MULTIPLE->SINGLE->KEY[9]->VALUE
4

1 回答 1

0

读一读,它将向您展示一个简短的教程

于 2012-10-16T18:50:52.783 回答