我有以下XML示例文件,我试图使用PHP显示:
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<record>
<field value="AAA" name="name"/>
<field value="5442.20" name="price"/>
<field value="5442.20" name="prev_close"/>
<field value="0.00" name="movement"/>
<field value="0.00" name="pct_move"/>
</record>
<record>
<record>
<data>
以下是应该遍历一些XML记录的PHP代码
<?php
$xml = 'http://feeds.xxx.com/aaa.asmx/getprices?CompanyKey=XYZ&subfeed=0';
$obj = simplexml_load_file($xml);
foreach ($obj->record as $value)
{
foreach( $value->field as $a )
{
foreach( $a[0]->attributes() as $b )
{
echo $b->name."<br>";
echo $b->price."<br>";
echo $b->movement."<br>";
echo $b->pct_move."<br>";
}
}
}
?>
我们将非常感谢您的协助。