Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple XML reading question (PHP)
    text
    copied!<p>I have the following XML file:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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; &lt;request&gt; &lt;address&gt;2114 Bigelow Ave&lt;/address&gt; &lt;citystatezip&gt;Seattle, WA&lt;/citystatezip&gt; &lt;/request&gt; &lt;message&gt; &lt;text&gt;Request successfully processed&lt;/text&gt; &lt;code&gt;0&lt;/code&gt; &lt;/message&gt; &lt;response&gt; &lt;results&gt; &lt;result&gt; &lt;zpid&gt;48749425&lt;/zpid&gt; &lt;links&gt; &lt;homedetails&gt;http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/&lt;/homedetails&gt; &lt;graphsanddata&gt;http://www.zillow.com/homedetails/charts/48749425_zpid,1year_chartDuration/?cbt=3697699817560038867%7E3%7EQh4sEjEhBNEguUWA-0f22TvGUpBB7FpUkAZlBRy5_26R5PYjKDdVAA**&lt;/graphsanddata&gt; &lt;mapthishome&gt;http://www.zillow.com/homes/48749425_zpid/&lt;/mapthishome&gt; &lt;myestimator&gt;http://www.zillow.com/myestimator/Edit.htm?zprop=48749425&lt;/myestimator&gt; &lt;myzestimator deprecated="true"&gt;http://www.zillow.com/myestimator/Edit.htm?zprop=48749425&lt;/myzestimator&gt; &lt;comparables&gt;http://www.zillow.com/homes/comps/48749425_zpid/&lt;/comparables&gt; &lt;/links&gt; &lt;address&gt; &lt;street&gt;2114 Bigelow Ave N&lt;/street&gt; &lt;zipcode&gt;98109&lt;/zipcode&gt; &lt;city&gt;Seattle&lt;/city&gt; &lt;state&gt;WA&lt;/state&gt; &lt;latitude&gt;47.63793&lt;/latitude&gt; &lt;longitude&gt;-122.347936&lt;/longitude&gt; &lt;/address&gt; &lt;zestimate&gt; &lt;amount currency="USD"&gt;1112500&lt;/amount&gt; &lt;last-updated&gt;01/14/2010&lt;/last-updated&gt; &lt;oneWeekChange deprecated="true"&gt;&lt;/oneWeekChange&gt; &lt;valueChange duration="30" currency="USD"&gt;-77500&lt;/valueChange&gt; &lt;valuationRange&gt; &lt;low currency="USD"&gt;878875&lt;/low&gt; &lt;high currency="USD"&gt;1145875&lt;/high&gt; &lt;/valuationRange&gt; &lt;percentile&gt;0&lt;/percentile&gt; &lt;/zestimate&gt; &lt;localRealEstate&gt; &lt;region id="271856" type="neighborhood" name="East Queen Anne"&gt; &lt;zindexValue&gt;525,252&lt;/zindexValue&gt; &lt;zindexOneYearChange&gt;-0.104&lt;/zindexOneYearChange&gt; &lt;links&gt; &lt;overview&gt;http://www.zillow.com/local-info/WA-Seattle/East-Queen-Anne/r_271856/&lt;/overview&gt; &lt;forSaleByOwner&gt;http://www.zillow.com/homes/fsbo/East-Queen-Anne-Seattle-WA/&lt;/forSaleByOwner&gt; &lt;forSale&gt;http://www.zillow.com/homes/for_sale/East-Queen-Anne-Seattle-WA/&lt;/forSale&gt; &lt;/links&gt; &lt;/region&gt; &lt;region id="16037" type="city" name="Seattle"&gt; &lt;zindexValue&gt;373,795&lt;/zindexValue&gt; &lt;zindexOneYearChange&gt;-0.064&lt;/zindexOneYearChange&gt; &lt;links&gt; &lt;overview&gt;http://www.zillow.com/local-info/WA-Seattle/r_16037/&lt;/overview&gt; &lt;forSaleByOwner&gt;http://www.zillow.com/homes/fsbo/Seattle-WA/&lt;/forSaleByOwner&gt; &lt;forSale&gt;http://www.zillow.com/homes/for_sale/Seattle-WA/&lt;/forSale&gt; &lt;/links&gt; &lt;/region&gt; &lt;region id="59" type="state" name="Washington"&gt; &lt;zindexValue&gt;256,760&lt;/zindexValue&gt; &lt;zindexOneYearChange&gt;-0.074&lt;/zindexOneYearChange&gt; &lt;links&gt; &lt;overview&gt;http://www.zillow.com/local-info/WA-home-value/r_59/&lt;/overview&gt; &lt;forSaleByOwner&gt;http://www.zillow.com/homes/fsbo/WA/&lt;/forSaleByOwner&gt; &lt;forSale&gt;http://www.zillow.com/homes/for_sale/WA/&lt;/forSale&gt; &lt;/links&gt; &lt;/region&gt; &lt;/localRealEstate&gt; &lt;/result&gt; &lt;/results&gt; &lt;/response&gt; &lt;/SearchResults:searchresults&gt; &lt;!-- H:118 T:102ms S:1761 R:Fri Jan 15 10:52:49 PST 2010 B:3.0.79367-comp_rel_b --&gt; </code></pre> <p>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. </p> <p>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:</p> <pre><code>$xml = simplexml_load_file("-truncated XML URL-"); $result = $xml-&gt;xpath('/SearchResults:searchresults/request/address') </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload