troubleshooting Question

Parsing XML (RSS Feed)

Avatar of go3team
go3team asked on
PHPXML
29 Comments1 Solution1626 ViewsLast Modified:
I'm trying to parse an RSS feed that is queried for weather for whatever location.  I've tried a few ways but am stuck where there is a colon in the tag, specifically the tag with aws:weather, and the information in that tag, to be broken down, and have a variable for each "sub-tag"(?).

Thanks.
<-XML->
 
<rss version="2.0" xmlns:georss="http://www.georss.org/georss">
 <channel>
     
        <title>Observations from Richmond,  VA - USA</title>
     
     
     <link>http://weather.weatherbug.com/VA/Richmond-weather.html?ZCode=Z5546&amp;Units=0&amp;stat=RRHMN</link>
     <description>Weatherbug, the owner of the world's largest weather network is now providing an API to it's weather data in the form of RSS. This will enable it's enthusiastic users to build their own applications.</description>
     <language>en-us</language>
 
     <lastBuildDate>Sat, 10 Jan 2009 06:00:00 GMT</lastBuildDate>
     <ttl>60</ttl>
     <aws:weather xmlns:aws="http://www.aws.com/aws"><aws:api version="2.0" /><aws:WebURL>http://weather.weatherbug.com/VA/Richmond-weather.html?ZCode=Z5546&amp;Units=0&amp;stat=RRHMN</aws:WebURL><aws:ob><aws:ob-date><aws:year number="2009" /><aws:month number="1" text="January" abbrv="Jan" /><aws:day number="10" text="Saturday" abbrv="Sat" /><aws:hour number="1" hour-24="01" /><aws:minute number="02" /><aws:second number="31" /><aws:am-pm abbrv="AM" /><aws:time-zone offset="-5" text="Eastern Standard Time" abbrv="EST" /></aws:ob-date><aws:requested-station-id /><aws:station-id>RRHMN</aws:station-id><aws:station>Ruby F. Carver ES</aws:station><aws:city-state zipcode="23238">Richmond,  VA</aws:city-state><aws:country>USA</aws:country><aws:latitude>37.6041666666667</aws:latitude><aws:longitude>-77.6269444444444</aws:longitude><aws:site-url>http://www.henrico.k12.va.us/es/carver/</aws:site-url><aws:aux-temp units="&amp;deg;F">74</aws:aux-temp><aws:aux-temp-rate units="&amp;deg;F">-0.2</aws:aux-temp-rate><aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond034.gif">Mostly Cloudy </aws:current-condition><aws:dew-point units="&amp;deg;F">29</aws:dew-point><aws:elevation units="ft">200</aws:elevation><aws:feels-like units="&amp;deg;F">35</aws:feels-like><aws:gust-time><aws:year number="2009" /><aws:month number="1" text="January" abbrv="Jan" /><aws:day number="9" text="Friday" abbrv="Fri" /><aws:hour number="12" hour-24="12" /><aws:minute number="00" /><aws:second number="00" /><aws:am-pm abbrv="PM" /><aws:time-zone offset="-5" text="Eastern Standard Time" abbrv="EST" /></aws:gust-time><aws:gust-direction>WSW</aws:gust-direction><aws:gust-speed units="mph">4</aws:gust-speed><aws:humidity units="%">79</aws:humidity><aws:humidity-high units="%">83.6</aws:humidity-high><aws:humidity-low units="%">77.9</aws:humidity-low><aws:humidity-rate>-4.1</aws:humidity-rate><aws:indoor-temp units="&amp;deg;F">83</aws:indoor-temp><aws:indoor-temp-rate units="&amp;deg;F">+0.0</aws:indoor-temp-rate><aws:light>0</aws:light><aws:light-rate>+0.0</aws:light-rate><aws:moon-phase moon-phase-img="http://api.wxbug.net/images/moonphase/mphase14.gif">-98</aws:moon-phase><aws:pressure units="&quot;">30.2</aws:pressure><aws:pressure-high units="&quot;">30.22</aws:pressure-high><aws:pressure-low units="&quot;">30.20</aws:pressure-low><aws:pressure-rate units="&quot;/h">-0.02</aws:pressure-rate><aws:rain-month units="&quot;">0.76</aws:rain-month><aws:rain-rate units="&quot;/h">0.00</aws:rain-rate><aws:rain-rate-max units="&quot;/h">0.00</aws:rain-rate-max><aws:rain-today units="&quot;">0.00</aws:rain-today><aws:rain-year units="&quot;">0.76</aws:rain-year><aws:temp units="&amp;deg;F">35.2</aws:temp><aws:temp-high units="&amp;deg;F">35</aws:temp-high><aws:temp-low units="&amp;deg;F">33</aws:temp-low><aws:temp-rate units="&amp;deg;F/h">+2.2</aws:temp-rate><aws:sunrise><aws:year number="2009" /><aws:month number="1" text="January" abbrv="Jan" /><aws:day number="10" text="Saturday" abbrv="Sat" /><aws:hour number="7" hour-24="07" /><aws:minute number="25" /><aws:second number="40" /><aws:am-pm abbrv="AM" /><aws:time-zone offset="-5" text="Eastern Standard Time" abbrv="EST" /></aws:sunrise><aws:sunset><aws:year number="2009" /><aws:month number="1" text="January" abbrv="Jan" /><aws:day number="10" text="Saturday" abbrv="Sat" /><aws:hour number="5" hour-24="17" /><aws:minute number="10" /><aws:second number="52" /><aws:am-pm abbrv="PM" /><aws:time-zone offset="-5" text="Eastern Standard Time" abbrv="EST" /></aws:sunset><aws:wet-bulb units="&amp;deg;F">33.08</aws:wet-bulb><aws:wind-speed units="mph">2</aws:wind-speed><aws:wind-speed-avg units="mph">2</aws:wind-speed-avg><aws:wind-direction>WSW</aws:wind-direction><aws:wind-direction-avg>WSW</aws:wind-direction-avg></aws:ob></aws:weather>
 
     <image>
     <title>Local Weather from WeatherBug</title>
     <width>142</width>
     <height>18</height>
     <link>http://weather.weatherbug.com/VA/Richmond-weather.html?ZCode=Z5546&amp;Units=0&amp;stat=RRHMN</link>
     <url>http://www.weatherbug.com/aws/imagesHmPg0604/img_wxbug_logo_whiteBG.gif</url>
 
     </image>
     
     
               <item>
               
                            <title>Live Conditions from Richmond,  VA - USA</title>                        
                         
                         <link>http://weather.weatherbug.com/VA/Richmond-weather.html?ZCode=Z5546&amp;Units=0&amp;stat=RRHMN</link>
                         <pubDate>Sat, 10 Jan 2009 06:02:31 GMT</pubDate>
                         <description><![CDATA[
                             
                                 <img src="http://deskwx.weatherbug.com/images/Forecast/icons/cond034.gif" border="0" alt="Current Conditions"/>&nbsp;&nbsp;&nbsp;
					                    <b>Mostly Cloudy </b> <br />
			                 		    
			                 <b>Temperature:</b> 35.2 &deg;F&nbsp;&nbsp;	
			                <br />
				                <b>Humidity:</b> 79 %&nbsp;&nbsp;
				                <b>Wind Speed:</b> 2 mph WSW&nbsp;&nbsp;
				                <b>Pressure:</b> 30.2 &quot;&nbsp;&nbsp;
			                <br />	
				                <b>Dew Point:</b> 29 &deg;F &nbsp;&nbsp;
				                <b>Gusts:</b> 4 mph WSW &nbsp;&nbsp;
				                <b>Rain Today:</b> 0.00 &quot; &nbsp;&nbsp;
			                <br />
                         ]]></description>
                         <georss:point>37.6041666666667 -77.6269444444444</georss:point>
 
                          <guid isPermaLink="false">Sat, 10 Jan 2009 06:02:44 GMT-Station1</guid>
                     
                  
                  </item>
               
 </channel>
</rss>
 
 
<-PHP->
 
$url1="http://xxx.xxx.xxx";
		
                $output = file_get_contents($ur1l);
                $xml = simplexml_load_string($output);
                $title = $xml->channel->aws:weather;
                $descrip = $xml->channel->item->description;
		$link = $xml->channel->item->link;
		$pubdate = $xml->channel->item->pubdate;
                $staid = $xml->channel->item->aws:station-id;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 29 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 29 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros