0
Hiyo,如何將這個XML解析到PHP
我經常與XML和PHP,但我發現被拋出的弧線球爲如何讓它在PHP這個特定的返回工作。如果我可以將「$ attribute」和「VALUE」轉換爲assoc數組,我會很喜歡。
真的難倒和沮喪 -Ray
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
)
)
)
UPDATE: 下面是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
http://stackoverflow.com/questions/7778814/simplexml-php-convert-simplexmlobject-into-php-array/7778950#7778950 – dfsq
發佈你的XML和預期產出,而不是輸出的var_dump。 – anubhava
增加該問題的更新 – Ray