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) { }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀