我正在尝试从 xml 文件获取数据,但遇到了麻烦,因为该表的级别比我能找到的示例要多一些。
我希望能够迭代<Event>as的每个实例<Information>,并且<Events>仅打开和关闭数据。<Event>根据记录的事件数量重复。
表结构的示例是:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Information>
<Events>
<Event>
<Time>3141.29</Time>
<PrimaryObject ID="487">
<Name>Player1</Name>
<Country>us</Country>
</PrimaryObject>
<Action>Move</Action>
<SecondaryObject ID="814">
<Name>Dog</Name>
<Parent>487</Parent>
</SecondaryObject>
</Event>
</Events>
</Information>
PHP代码是:
<!DOCTYPE html>
<html>
<body>
<?php
$xml=simplexml_load_file("data.xml") or die("Error: Cannot create object");
foreach($xml->Event as $events) {
$id = $events->PrimaryObject->attributes();
$name = $events->PrimaryObject->Name;
...
echo $id['ID'].' '. $name;
echo "<br>";
}
?>
</body>
</html>
繁星点点滴滴
慕桂英546537