我在使用 xpath 和 XML 时遇到问题
这是 XML 文件的示例
<OddService>
<Header>
<Status>000</Status>
<Description>OK</Description>
<Timestamp>1352407434</Timestamp>
</Header>
<Results>
<Event>
<EventID>1182745</EventID>
<StartDate>2012-11-09T19:45:00</StartDate>
<SportID>6046</SportID>
<LeagueID>1182547</LeagueID>
<LocationID>243</LocationID>
<Status>NSY</Status>
<LastUpdate>2012-11-08T20:27:14.767</LastUpdate>
<HomeTeam ID="7" Name="Middlesbrough" Logo=""/>
<AwayTeam ID="992" Name="Sheffield W" Logo=""/>
<Scores status="" time=""/>
<Scorers/>
<Cards/>
<Outcomes>...</Outcomes>
</Event>
<OddService>
<Header>
<Status>000</Status>
<Description>OK</Description>
<Timestamp>1352407434</Timestamp>
</Header>
<Results>
<Event>
<EventID>1182745</EventID>
<StartDate>2012-11-09T19:45:00</StartDate>
<SportID>6046</SportID>
<LeagueID>1182547</LeagueID>
<LocationID>243</LocationID>
<Status>NSY</Status>
<LastUpdate>2012-11-08T20:27:14.767</LastUpdate>
<HomeTeam ID="7" Name="Middlesbrough" Logo=""/>
<AwayTeam ID="992" Name="Sheffield W" Logo=""/>
<Scores status="" time=""/>
<Scorers/>
<Cards/>
<Outcomes>...</Outcomes>
</Event>
</Results>
</OddService>
在这个 XML 示例中,我只包含了其中一个条目。我正在使用这个 PHP 代码,但没有得到任何结果......有人有什么想法吗?
<?php
$loadfile = simplexml_load_file('matches.xml');
foreach ($loadfile->OddService->Results as $gameinfo):
$kodate=$gameinfo->StartDate;
$status=$gameinfo->Status;
$id=$gameinfo->EventID;
$league=$gameinfo->LeagueID;
$hometeam=$gameinfo->HomeTeam['Name'];
$awayteam=$gameinfo->AwayTeam['Name'];
$home=$gameinfo->Outcomes->Outcome->Bookmaker->Odds[0]['currentPrice'];
$away=$gameinfo->Outcomes->Outcome->Bookmaker->Odds[1]['currentPrice'];
$draw=$gameinfo->Outcomes->Outcome->Bookmaker->Odds[2]['currentPrice'];
?>
提前致谢!