duanfazhun0383 2012-10-29 22:48
浏览 38
已采纳

麻烦遍历XML文件节点

I have properly parsed one XML feed, and have inputted that data into a table on my site. However, I am dealing with a slightly more complicated feed, and am having trouble finding tree nodes.

XML Feed: http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=NFL

Declare variables:

$AwayLine = (string)$xml2->spread_visiting;  
$HomeLine = (string)$xml2->home_visiting;

From my understanding, the feed is broken down as(obviously, im wrong):

foreach ($xml2->event->period[0]->spread as $Spread) {  
    $AwayLine = $Spread->spread_visiting;   
    $HomeLine = $Spread->spread_home;  
}

Based on the XML path, every item is seen as an event. Every event has multiple periods. Every period has a spread. Every spread includes spread_visiting and spread_home. However, I only need the spreads in the first period, or period[0]

Any help would be greatly appreciated!

  • 写回答

1条回答 默认 最新

  • doulang2311 2012-10-29 22:54
    关注

    Both events and periods are missing from your statement, so it should be:

    foreach ($xml2->events->event as $event) {
        foreach ($event->periods->period[0]->spread as $spread) {
        }
    }
    

    Not 100% sure about it, but you might be able to write this as well:

    foreach ($xml2->events->event->periods->period[0]->spread as $spread) { }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统