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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了