2 回答
TA贡献1803条经验 获得超3个赞
您必须使用事件
$xml->Events->Event as $events
例如
$xml=simplexml_load_file("data.xml") or die("Error: Cannot create object");
foreach($xml->Events->Event as $events) {
$id = $events->PrimaryObject->attributes();
$name = $events->PrimaryObject->Name;
echo $id['ID'].' '. $name;
echo "<br>";
}
输出
487 Player1
TA贡献1848条经验 获得超10个赞
我不确定您到底在寻找什么数据,但这里有所有内容,使用 xpath,您可以选择:
$events = $xml->xpath('.//Event');
foreach($events as $event) {
$dat = $event->xpath('./PrimaryObject')[0];
$time= $event->xpath('./Time');
$id = $dat->xpath('./@ID');
$name = $dat->xpath('./Name');
$country = $dat->xpath('./Country');
$dat2 = $event->xpath('./SecondaryObject')[0];
$action= $event->xpath('./Action');
$id2 = $dat2->xpath('./@ID');
$name2 = $dat2->xpath('./Name');
$parent = $dat2->xpath('./Parent');
echo 'Time: ' . $time[0];
echo "<br>";
echo 'Action: ' . $action[0];
echo "<br>";
echo "<br>";
echo 'Primary Object Data:';
echo "<br>";
echo 'ID: ' . $id[0];
echo "<br>";
echo 'Name: ' . $name[0];
echo "<br>";
echo 'Country: ' . $country[0];
echo "<br>";
echo "<br>";
echo "<br>";
echo 'Secondary Object Data:';
echo "<br>";
echo 'ID: ' . $id2[0];
echo "<br>";
echo 'Name: ' . $name2[0];
echo "<br>";
echo 'Parent: ' . $parent[0];
echo "<br>";
}
输出:
Time: 3141.29
Action: Move
Primary Object Data:
ID: 487
Name: Player1
Country: us
Secondary Object Data:
ID: 814
Name: Dog
Parent: 487
- 2 回答
- 0 关注
- 125 浏览
添加回答
举报