PHP-如何读取此XML文件

PHP-如何读取此XML文件,php,xml,Php,Xml,我有以下xml: <CallOverview> <Calls Count="2"> <Call CallType="LandLine" Customer="this account" StartTime="2013-09-17 20:21:19 (UTC)" Destination="NL" Duration="00:00:05" Charge="0.045" CallId="158263673"/> <Call

我有以下xml:

<CallOverview>
    <Calls Count="2">
        <Call CallType="LandLine" Customer="this account" StartTime="2013-09-17 20:21:19 (UTC)" Destination="NL" Duration="00:00:05" Charge="0.045" CallId="158263673"/>
        <Call CallType="Mobile" Customer="this account" StartTime="2013-09-17 20:18:34 (UTC)" Destination="US" Duration="00:00:26" Charge="0.101" CallId="158263381"/>
    </Calls>
<MoreData>No more data available</MoreData>
</CallOverview>
我根据需要接收XML,但无法以正确的方式提取数据:

$xml=simplexml_load_string ( get_xml($url_post) ) ;

echo $xml->getName() . "<br>";

foreach($xml->children() as $child)
{
    echo $child->getName() . ": " . $child . "<br>";

    foreach($child->children() as $subchild)
    {
        echo $subchild->getName() . ": " . $subchild . "<br>";
        $role = array($subchild->attributes());

        foreach($subchild as $key => $value) {
            echo "$role $key $value";            
        }
    }
}
我试过:

foreach($xml->Call[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"\"\n";
}
但我得到了以下错误:

Fatal error: Call to a member function attributes() on a non-object
另外,如果没有呼叫,则不存在Call元素。
不熟悉xml,所以不确定是否可以在child下使用child

最后我使用了DOM解析器:

$dom_document = new DOMDocument();

$dom_document->loadXML(get_xml($url));

$searchNode = $dom_document->getElementsByTagName( "Call" );

if (!is_null($searchNode)) {
foreach( $searchNode as $searchNode )
{
    $Destination = $searchNode->getAttribute('Destination');
echo "$Destination";
}
}

会发生什么?什么意思
无法以正确的方式提取数据
?此代码输出什么?您希望它输出什么?我编辑了它,但不知怎么的,我没有从Callhm中获取属性。您在嵌套的foreach(更新的链接)中使用了两次$child
Fatal error: Call to a member function attributes() on a non-object
$dom_document = new DOMDocument();

$dom_document->loadXML(get_xml($url));

$searchNode = $dom_document->getElementsByTagName( "Call" );

if (!is_null($searchNode)) {
foreach( $searchNode as $searchNode )
{
    $Destination = $searchNode->getAttribute('Destination');
echo "$Destination";
}
}