views:

179

answers:

3

Hello, I have the following XML file:

    <?xml version="1.0" encoding="utf-8"?>
<SearchResults:searchresults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd /vstatic/279989c5e93d519f8d8f23d3f6cac661/static/xsd/SearchResults.xsd" xmlns:SearchResults="http://www.zillow.com/static/xsd/SearchResults.xsd"&gt;

<request>
<address>2114 Bigelow Ave</address>
<citystatezip>Seattle, WA</citystatezip>
</request>

<message>
<text>Request successfully processed</text>

<code>0</code>

</message>


<response>
<results>

<result>
<zpid>48749425</zpid>
<links>

<homedetails>http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/&lt;/homedetails&gt;

<graphsanddata>http://www.zillow.com/homedetails/charts/48749425_zpid,1year_chartDuration/?cbt=3697699817560038867%7E3%7EQh4sEjEhBNEguUWA-0f22TvGUpBB7FpUkAZlBRy5_26R5PYjKDdVAA**&lt;/graphsanddata&gt;

<mapthishome>http://www.zillow.com/homes/48749425_zpid/&lt;/mapthishome&gt;

<myestimator>http://www.zillow.com/myestimator/Edit.htm?zprop=48749425&lt;/myestimator&gt;
<myzestimator deprecated="true">http://www.zillow.com/myestimator/Edit.htm?zprop=48749425&lt;/myzestimator&gt;

<comparables>http://www.zillow.com/homes/comps/48749425_zpid/&lt;/comparables&gt;

</links>
<address>
<street>2114 Bigelow Ave N</street>
<zipcode>98109</zipcode>
<city>Seattle</city>
<state>WA</state>
<latitude>47.63793</latitude>

<longitude>-122.347936</longitude>
</address>


<zestimate>
<amount currency="USD">1112500</amount>
<last-updated>01/14/2010</last-updated>


<oneWeekChange deprecated="true"></oneWeekChange>


<valueChange duration="30" currency="USD">-77500</valueChange>



<valuationRange>
<low currency="USD">878875</low>
<high currency="USD">1145875</high>
</valuationRange>
<percentile>0</percentile>
</zestimate>
<localRealEstate>


<region id="271856" type="neighborhood" name="East Queen Anne">

<zindexValue>525,252</zindexValue>
<zindexOneYearChange>-0.104</zindexOneYearChange>

<links>
<overview>http://www.zillow.com/local-info/WA-Seattle/East-Queen-Anne/r_271856/&lt;/overview&gt;
<forSaleByOwner>http://www.zillow.com/homes/fsbo/East-Queen-Anne-Seattle-WA/&lt;/forSaleByOwner&gt;
<forSale>http://www.zillow.com/homes/for_sale/East-Queen-Anne-Seattle-WA/&lt;/forSale&gt;

</links>
</region>

<region id="16037" type="city" name="Seattle">

<zindexValue>373,795</zindexValue>
<zindexOneYearChange>-0.064</zindexOneYearChange>

<links>
<overview>http://www.zillow.com/local-info/WA-Seattle/r_16037/&lt;/overview&gt;

<forSaleByOwner>http://www.zillow.com/homes/fsbo/Seattle-WA/&lt;/forSaleByOwner&gt;
<forSale>http://www.zillow.com/homes/for_sale/Seattle-WA/&lt;/forSale&gt;
</links>
</region>

<region id="59" type="state" name="Washington">

<zindexValue>256,760</zindexValue>
<zindexOneYearChange>-0.074</zindexOneYearChange>


<links>
<overview>http://www.zillow.com/local-info/WA-home-value/r_59/&lt;/overview&gt;
<forSaleByOwner>http://www.zillow.com/homes/fsbo/WA/&lt;/forSaleByOwner&gt;
<forSale>http://www.zillow.com/homes/for_sale/WA/&lt;/forSale&gt;
</links>
</region>

</localRealEstate>

</result>

</results>          
</response>

</SearchResults:searchresults>
<!-- H:118  T:102ms  S:1761  R:Fri Jan 15 10:52:49 PST 2010  B:3.0.79367-comp_rel_b -->

If you can't already tell, it's the standard output of the Zillow API. I want to store the data of information stored between certain tags, which I have learned is queried through the xpath.

For example, how would I query for the data in /SearchResults:searchresults/request/address? Doing something like this doesn't work when I echo/print the variable:

$xml = simplexml_load_file("-truncated XML URL-");
$result = $xml->xpath('/SearchResults:searchresults/request/address')

From what I understand, the $result variable should contain the value found nested in that %VALUE HERE%, correct? But it prints "Array", and when I print_r, it returns blank.

+1  A: 

You need to use the full namespace not the short name.

prodigitalson
So what would my query look like, including the namespace?
dmanexe
`$xml->xpath('/SearchResults:http://www.zillow.com/static/xsd/SearchResults.xsd/request/address')`.
prodigitalson
+2  A: 

Here's a simple way to get that information:

<?php
    $xml = simplexml_load_file("test.xml");
    echo $xml->request->address;
?>
John Conde
Thanks, this works great! I wasn't aware of the simple method of getting the XML information through just $xml->Thanks a lot!
dmanexe
A: 

Use http://simplepie.org

$xml = "yourxml code here";

$feed = new SimplePie();
$feed->set_raw_data($xml);
$feed->init();
$feed->handle_content_type();
echo $feed->get_adress();
streetparade