你好,我想解析嵌套的xml,但我使用多个for循环来提取,但我没有找到它非常合适的方式。使用php解析嵌套的xml
我想根据唯一的ID来分析数据,并separte他们,但不能计算任何简单的方法是
,这里是我的xml
<propertyList date="2014-06-02-17:30:33" username="adsss" password="v147C0z5CBlw">
<business modTime="2014-06-02-12:22:32" status="current">
<agentID>TEST</agentID>
<uniqueID>1420648</uniqueID>
<listingAgent id="1">
<name>jonny</name>
<telephone type="BH"></telephone>
<telephone type="mobile"></telephone>
<email>[email protected]</email>
</listingAgent>
<listingAgent id="2"></listingAgent>
</business>
<business modTime="2014-05-16-15:11:41" status="current">
<agentID>TEST</agentID>
<uniqueID>1435201</uniqueID>
<listingAgent id="1">
<name>Mike Smith</name>
<telephone type="BH"></telephone>
<telephone type="mobile"></telephone>
<email>[email protected]</email>
</listingAgent><listingAgent id="2"></listingAgent>
</business>
</propertyList>
这里是我的代码
<?php
$xml=simplexml_load_file("myxmldata.xml");
echo "<pre>";
for($i=0;$i<count($xml);$i++):
echo "agentID=>".$xml->business[$i]->agentID;
echo "<br>";
echo "uniqueID=>".$xml->business[$i]->uniqueID;
echo "<br>";
endfor;
for($i=0;$i<count($xml->business->listingAgent);$i++):
echo "agentName=>".$xml->business->listingAgent[$i]->name;
endfor;
for($i=0;$i<count($xml->business->listingAgent->telephone);$i++):
echo "telephonetype=>".$xml->business->listingAgent->telephone[$i]->type;
endfor;
?>
看起来好吗?你面临的问题或预期的结果 –