douqian2524 2015-10-22 16:49
浏览 33
已采纳

simplexml循环空节点的属性条目

I have the following XML structure:

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

and in PHP:

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

returns "Invalid argument supplied for foreach()"

can I loop through those children with SimpleXML? and yes there is no space in at the end of the line near to /> .. is that a problem? I just get the data and I have to parse it....

  • 写回答

1条回答 默认 最新

  • drl57959 2015-10-22 18:38
    关注

    $xml contains your root node <parent>, so do:

    foreach ($xml->child as $item) 
    

    the closing tag /> is correct.

    see https://eval.in/455645

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料