Simplexml循环空节点条目的属性


simplexml loop empty nodes entry for attributes

我有以下XML结构:

<parent>
    <child foo="bar1" foo2="bar2"/>
    <child foo="bar3" foo2="bar4"/>
</parent>

和PHP中的

foreach ($xml->parent->child as $item) 

返回"为foreach()提供的无效参数"

我可以循环通过那些孩子与SimpleXML?是的,在/>附近的行末尾没有空格。这是个问题吗?获取数据,然后解析....

$xml包含根节点<parent>,因此:

foreach ($xml->child as $item) 

结束标签/>是正确的。

见https://eval.in/455645