Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php XML源。。。我哪里做错了?_Php_Simplexml - Fatal编程技术网

Php XML源。。。我哪里做错了?

Php XML源。。。我哪里做错了?,php,simplexml,Php,Simplexml,最近,我在使用feed和PHP时遇到的问题很少,但这让我感到困惑 XML看起来像这样 <Order> <Booking id="272591086"/> </Order> 我的PHP如下所示,但没有显示上面XML中的预订id,我哪里出错了 <?php $theurl = 'http://www.website.co.uk/dev/test.xml'; $xml = simplexml_load_file($theurl); $result

最近,我在使用feed和PHP时遇到的问题很少,但这让我感到困惑

XML看起来像这样

<Order>
    <Booking id="272591086"/>
</Order>

我的PHP如下所示,但没有显示上面XML中的预订id,我哪里出错了

<?php
$theurl = 'http://www.website.co.uk/dev/test.xml';
$xml = simplexml_load_file($theurl);
$result = $xml->xpath("/Order/Booking");
foreach ($result as $ref) 
{
   echo 'Booking Ref '. $ref['id'] .'';
}
?>

我支持@Gordon的评论,但如果XML实际上就是您正在显示的XML,请在XPATH查询中尝试以下调整:

$result = $xml->xpath("//Booking");

适用于我:,因此逻辑上的解释是,您正在加载的URL没有提供您正在显示的XML。通过将您的XML代码放入“test.XML”并添加
$theurl=“test.XML”
,它也适用于我