Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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_Html_Xml - Fatal编程技术网

使用php访问xml数据时遇到困难

使用php访问xml数据时遇到困难,php,html,xml,Php,Html,Xml,我正在使用房地产api编写一个简单的应用程序。这是我第一次使用api,也是第一次使用xml 我想我遗漏了xml文件中的作用域,但我不确定。我试图实现的目标是呼应城市的名称 This XML file does not appear to have any style information associated with it. The document tree is shown below. <TruliaWebServices> <request> <Para

我正在使用房地产api编写一个简单的应用程序。这是我第一次使用api,也是第一次使用xml

我想我遗漏了xml文件中的作用域,但我不确定。我试图实现的目标是呼应城市的名称

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<TruliaWebServices>
<request>
<Parameter>
<index>1</index>
<name>library</name>
<value>TruliaStats</value>
</Parameter>
<Parameter>
<index>2</index>
<name>function</name>
<value>getCityStats</value>
</Parameter>
<Parameter>
<index>3</index>
<name>city</name>
<value>San Diego=CA</value>
</Parameter>
<Parameter>
<index>4</index>
<name>state</name>
<value>CA</value>
</Parameter>
<Parameter>
<index>5</index>
<name>startDate</name>
<value>2014-05-06</value>
</Parameter>
<Parameter>
<index>6</index>
<name>endDate</name>
<value>2014-09-03</value>
</Parameter>
<Parameter>
<index>7</index>
<name>statType</name>
<value>listings</value>
</Parameter>
<Parameter>
<index>8</index>
<name>apikey</name>
<value>auww6cdtukpkm8j824eqbrh6</value>
</Parameter>
</request>
<response>
<TruliaStats>
<location>
<city>San Diego=CA</city>
<state>CA</state>
<searchResultsURL>http://www.trulia.com/CA/San_Diego%3DCA/</searchResultsURL>
<cityGuideURL>
http://www.trulia.com/real_estate/San_Diego%3DCA-California/
</cityGuideURL>
<heatMapURL>
http://www.trulia.com/home_prices/California/San_Diego%3DCA-heat_map/
</heatMapURL>
</location>
<listingStats/>
</TruliaStats>
</response>
</TruliaWebServices>
此XML文件似乎没有任何与之关联的样式信息。文档树如下所示。
1.
图书馆
块茎
2.
功能
getCityStats
3.
城市
圣地亚哥=加利福尼亚州
4.
状态
加利福尼亚州
5.
起始日期
2014-05-06
6.
实际结束
2014-09-03
7.
statType
列表
8.
阿皮基
auww6cdtukpkm8j824eqbrh6
圣地亚哥=加利福尼亚州
加利福尼亚州
http://www.trulia.com/CA/San_Diego%3DCA/
http://www.trulia.com/real_estate/San_Diego%3DCA-加州/
http://www.trulia.com/home_prices/California/San_Diego%3DCA-热图/
这是我的php代码

<?php 
        $url = "http://api.trulia.com/webservices.php?library=TruliaStats&function=getCityStats%20&city=San%20Diego=CA&state=CA&startDate=2014-05-06&endDate=2014-09-03&statType=listings&apikey=ssssssssssssssss";
        $xml = simplexml_load_file($url);
        echo $xml->TruliaWebServices->response->TruliaStats->location->city;


?>

只需从echo中删除根节点(
TruliaWebServices
),这是不需要的

print_r($xml->response->TruliaStats->location->city);  // San Diego