使用SimpleXML解析XML不会返回任何内容 [英] Parsing XML with SimpleXML returns nothing

查看:40
本文介绍了使用SimpleXML解析XML不会返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试分析MapQuest流量API,但当我尝试显示事件时,什么也不显示,如果我在php中显示"If Empty",它将返回Empty。

代码如下:

    <?php
    $mysongs = simplexml_load_file("http://www.mapquestapi.com/traffic/v1/incidents?key=Fmjtd%7Cluuan1u2nh%2C2a%3Do5-96rw5u&callback=handleIncidentsResponse&boundingBox=$_GET[a], $_GET[b], $_GET[c], $_GET[d]&filters=construction,incidents&inFormat=kvp&outFormat=xml");
echo $mysongs->Incidents[0]->Incident[0]->fullDesc;
?>

我传递的参数:?a=33.352532499999995&;b=-118.2324383&;c=34.352532499999995&;d=-117.2324383.

提前谢谢!

test.xml

此处推荐答案_LOAD_FILE没有加载所有的xml数据,因此,我创建了一个名为test.xml的xml文件,然后从test.xml加载数据。现在您可以打印所需的数据。

<?php


  $a = $_GET['a'];
  $b = $_GET['b'];
  $c = $_GET['c'];
  $d = $_GET['d'];

   $xml_feed_url = 'http://www.mapquestapi.com/traffic/v1/incidents?key=Fmjtd|luuan1u2nh%2C2a%3Do5-96rw5u&callback=handleIncidentsResponse&boundingBox='.$a.','.$b.','.$c.','.$d.'&filters=construction,incidents&inFormat=kvp&outFormat=xml';
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
   curl_setopt($ch, CURLOPT_HEADER, false);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $xml = curl_exec($ch);
   curl_close($ch);


            $xml2 = new SimpleXMLElement($xml); 

            $xml2->asXML("test.xml");
            $xml2->asXML();

    $mysongs = simplexml_load_file("test.xml"); 
    print_r($mysongs);      
?>

这篇关于使用SimpleXML解析XML不会返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆