Php 在SimpleXML不工作的情况下访问XML文件

Php 在SimpleXML不工作的情况下访问XML文件,php,xml,Php,Xml,当我与yahoo weather进行API调用时,返回了以下xml。为什么我回显$out时会出现空白 $endpoint = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D%20560743&diagnostics=true'; $xml = simplexml_load_file($endpoint) or die('fail

当我与yahoo weather进行API调用时,返回了以下xml。为什么我回显$out时会出现空白

 $endpoint = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D%20560743&diagnostics=true';


 $xml = simplexml_load_file($endpoint) or die('failed to load xml');
 $out = $xml -> query -> diagnostics -> publiclyCallable;

 echo $out;
返回的XML:

 This XML file does not appear to have any style information associated with it. The document tree is shown below.
 <query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="1" yahoo:created="2017-02-10T11:54:56Z" yahoo:lang="en-US">

 <diagnostics>
    <publiclyCallable>true</publiclyCallable>
    <url execution-start-time="1" execution-stop-time="7" execution-time="6">...</url>
    <user-time>8</user-time>
    <service-time>6</service-time>
    <build-version>2.0.92</build-version>
 </diagnostics>
 <results>...</results>
 </query>
此XML文件似乎没有任何与之关联的样式信息。文档树如下所示。
真的
...
8.
6.
2.0.92
...

删除
查询
,因为
$xml
已经表示它:

$endpoint = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D%20560743&diagnostics=true';
$xml = simplexml_load_file($endpoint) or die('failed to load xml');
$out = $xml -> diagnostics -> publiclyCallable;
echo $out;    // `true`

XML似乎无效,请在将收到的字符串传递给之前删除第一行

simplexml_加载_文件()

作用