请任何人帮助我如何从下面的xml文档中检索数据
<?xml version="1.0" encoding="utf-8"?>
<livescore-feed timestamp-created="1279745722">
<item id="afab6479053955afcd07dbe2eb972feb" status= "finished" timestamp-starts= "1278255600">
<teams>
<hosts id="zenspbfc_rus">
<name>Zenit</name>
<fullname>FC Zenit St. Petersburg</fullname>
</hosts>
<guests id="anzmfc_rus">
<name>Anzhi</name>
<fullname>FC Anzhi Makhachkala </fullname>
</guests>
</teams>
<events>
<event type="goal" team="hosts">
<player>Bystrov</player>
<minute>15</minute>
<score>1 - 0</score>
</event>
<event type="yellow_card" team="guests">
<player>Tsorayev</player>
<minute>40</minute>
</event>
</events>
</item>
</livescore-feed>
我已经尝试了以下内容并且我能够获得一些数据,除了从事件节点,事件包含一些节点事件。我遇到的问题是如何从事件节点
获取事件$xml = simplexml_load_string($data);
$match_id = $xml->{livescorefullname-feed}->matches->item[$i]['id'];
echo $match_id;
答案 0 :(得分:0)
在SimpleXML中,您不指定根节点,因为SimpleXML对象($xml
)是根节点。
这会遍历每个事件并输出详细信息。
foreach($xml->item->events->event as $event){
echo $event->score;
echo $event->player;
echo $event->attributes()->type;
echo $event->attributes()->team;
}