【问题标题】:simplexml loop empty nodes entry for attributes属性的 simplexml 循环空节点条目
【发布时间】:2015-10-23 02:46:14
【问题描述】:

我有以下 XML 结构:

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

在 PHP 中:

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

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

我可以用 SimpleXML 遍历那些孩子吗? 是的,在 /> 附近的行尾没有空格 .. 有问题吗?我只是得到数据,我必须解析它....

【问题讨论】:

  • 那是你的完整 xml 吗?你能提供你实例化 $xml 对象的代码吗?

标签: php xml simplexml


【解决方案1】:

$xml 包含你的根节点&lt;parent&gt;,所以这样做:

foreach ($xml->child as $item) 

结束标签/&gt;是正确的。

https://eval.in/455645

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2017-06-10
    • 2014-02-18
    • 1970-01-01
    • 2013-07-11
    相关资源
    最近更新 更多