I have some weather xml that I am trying to parse via php loop.
The problem is that I am able to access all nodes except
<aws:weather xmlns:aws="http://www.aws.com/aws>
I cannot drill down into this node. Is it because of the url?
I ultimatly need to access this node
<aws:station> Salinas Municipal Airport <aws:station>
This is the php that I have:
<?php
$html = "";
$url = "http://i.wxbug.net/REST/SP/" .
"getLiveWeatherRSS.aspx?api_key=sdfgdsgd5454&stationid=SLNAS";
$xml = simplexml_load_file($url);
for ($i = 0; $i < 10; $i++) {
$aws:station = $xml->channel->aws:weather->aws:ob[$i]->aws:station;
$html .= "<h3>$aws:station</h3>";
}
echo $html;
?>
This is the xml
<rss xmlns:georss="http://www.georss.org/georss" version="2.0">
<channel>
<title>Observations from Salinas, CA - USA</title>
<link>...</link>
<description>...</description>
<language>en-us</language>
<lastBuildDate>Tue, 29 May 2012 17:00:00 GMT</lastBuildDate>
<ttl>60</ttl>
<aws:weather xmlns:aws="http://www.aws.com/aws">
<aws:api version="2.0"/>
<aws:WebURL>...</aws:WebURL>
<aws:InputLocationURL>...</aws:InputLocationURL>
<aws:ob>
<aws:ob-date>...</aws:ob-date>
<aws:requested-station-id>SLNAS</aws:requested-station-id>
<aws:station-id>KSNS</aws:station-id>
<aws:station>Salinas Municipal Airport</aws:station>
<aws:city-state zipcode="93905">Salinas, CA</aws:city-state>
<aws:country>USA</aws:country>
<aws:latitude>36.6633338928223</aws:latitude>
<aws:longitude>-121.608055114746</aws:longitude>
<aws:site-url/>
<aws:aux-temp units="°F">0</aws:aux-temp>
<aws:aux-temp-rate units="°F">-52.9</aws:aux-temp-rate>
<aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons
/cond000.gif">Clear</aws:current-condition>
<aws:dew-point units="°F">45</aws:dew-point>
<aws:elevation units="ft">66</aws:elevation>
<aws:feels-like units="°F"/>
<aws:gust-time>...</aws:gust-time>
<aws:gust-direction>WNW</aws:gust-direction>
<aws:gust-direction-degrees>281</aws:gust-direction-degrees>
<aws:gust-speed units="mph">N/A</aws:gust-speed>
<aws:humidity units="%">60</aws:humidity>
<aws:humidity-high units="%">6</aws:humidity-high>
<aws:humidity-low units="%">6</aws:humidity-low>
<aws:humidity-rate>0</aws:humidity-rate>
<aws:indoor-temp units="°F">0</aws:indoor-temp>
<aws:indoor-temp-rate units="°F">0</aws:indoor-temp-rate>
<aws:light>0</aws:light>
<aws:light-rate>0</aws:light-rate>
<aws:moon-phase moon-phase-img="http://api.wxbug.net/images/moonphase
/mphase09.gif">-61</aws:moon-phase>
<aws:pressure units=""">30.08</aws:pressure>
<aws:pressure-high units=""">30.08</aws:pressure-high>
<aws:pressure-low units=""">30.05</aws:pressure-low>
<aws:pressure-rate units=""/h">0</aws:pressure-rate>
<aws:rain-month units=""">0</aws:rain-month>
<aws:rain-rate units=""/h">0</aws:rain-rate>
<aws:rain-rate-max units=""/h">0</aws:rain-rate-max>
<aws:rain-today units=""">0</aws:rain-today>
<aws:rain-year units=""">0</aws:rain-year>
<aws:temp units="°F">59</aws:temp>
<aws:temp-high units="°F">59</aws:temp-high>
<aws:temp-low units="°F">51</aws:temp-low>
<aws:temp-rate units="°F/h">0</aws:temp-rate>
<aws:sunrise>
<aws:year number="2012"/>
<aws:month number="5" text="May" abbrv="May"/>
<aws:day number="29" text="Tuesday" abbrv="Tue"/>
<aws:hour number="5" hour-24="05"/>
<aws:minute number="50"/>
<aws:second number="01"/>
<aws:am-pm abbrv="AM"/>
<aws:time-zone offset="-7" text="Pacific Daylight Time (USA)" abbrv="PDT"/>
</aws:sunrise>
<aws:sunset>
<aws:year number="2012"/>
<aws:month number="5" text="May" abbrv="May"/>
<aws:day number="29" text="Tuesday" abbrv="Tue"/>
<aws:hour number="8" hour-24="20"/>
<aws:minute number="18"/>
<aws:second number="10"/>
<aws:am-pm abbrv="PM"/>
<aws:time-zone offset="-7" text="Pacific Daylight Time (USA)" abbrv="PDT"/>
</aws:sunset>
<aws:wet-bulb units="°F">51.602</aws:wet-bulb>
<aws:wind-speed units="mph">N/A</aws:wind-speed>
<aws:wind-speed-avg units="mph">N/A</aws:wind-speed-avg>
<aws:wind-direction>WNW</aws:wind-direction>
<aws:wind-direction-degrees>279</aws:wind-direction-degrees>
<aws:wind-direction-avg>WNW</aws:wind-direction-avg>
</aws:ob>
</aws:weather>
<image>...</image>
<item>...</item>
</channel>
</rss>
The problem is caused by the aws namespace in the XML document.
You could use the
childerenmethod to fetch all nodes that belong to the namespace, than access those.You can find a more detailed problem description at http://www.sitepoint.com/simplexml-and-namespaces/