将以下结构作为XML:
<USERS COUNT="3" >
<USER FIRST_NAME="asdsd" ROLEID="10" EMAIL="blub2@fasel.com" STATUS="ACTIVE" LAST_NAME="asda" USERID="100" >
<LOCATION LOCATIONID="9" NAME="Test Users" SORT_ORDER="0" ></LOCATION>
</USER>
<USER FIRST_NAME="gffgh" ROLEID="10" EMAIL="blub@fasel.de" STATUS="ACTIVE" LAST_NAME="fghfgh" USERID="99" >
<LOCATION LOCATIONID="9" NAME="Test Users" SORT_ORDER="0" ></LOCATION>
</USER>
<USER FIRST_NAME="Hilmi" ROLEID="8" EMAIL="xxx@xxx.com" STATUS="ACITVE" LAST_NAME="xxx" USERID="98" >
<LOCATION LOCATIONID="9" NAME="Test Users" SORT_ORDER="0" ></LOCATION>
</USER>
</USERS>
这一行
simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
产生以下对象:
SimpleXMLElement Object
(
[USERS] => SimpleXMLElement Object
(
[@attributes] => Array
(
[COUNT] => 3
)
[USER] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[FIRST_NAME] => asdsd
[ROLEID] => 10
[EMAIL] => blub2@fasel.com
[STATUS] => ACTIVE
[LAST_NAME] => asda
[USERID] => 100
)
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[LOCATIONID] => 9
[NAME] => Test Users
[SORT_ORDER] => 0
)
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[FIRST_NAME] => gffgh
[ROLEID] => 10
[EMAIL] => blub@fasel.de
[STATUS] => ACTIVE
[LAST_NAME] => fghfgh
[USERID] => 99
)
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[LOCATIONID] => 9
[NAME] => Test Users
[SORT_ORDER] => 0
)
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[FIRST_NAME] => Hilmi
[ROLEID] => 8
[EMAIL] => xxx@xxx.com
[STATUS] => ACITVE
[LAST_NAME] => Hilmiev
[USERID] => 98
)
[LOCATION] => SimpleXMLElement Object
(
[@attributes] => Array
(
[LOCATIONID] => 9
[NAME] => Test Users
[SORT_ORDER] => 0
)
)
)
)
)
)
<LOCATION>
子元素#1和#2转换为[0]
和[1]
,最后一个(始终只是最后一个)转换为[LOCATION]
< / p>
PHP版本5.5.14
我本来期待像
这样的东西SimpleXMLElement Object
(
[USERS] => SimpleXMLElement Object
(
[@attributes] => Array
...
[USER] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
...
)
[LOCATION] => SimpleXMLElement Object
表示所有子元素。
有没有人对此有解释?