Hello,
I am having problems trying to get a field from a XML file.
I can load the XML file into my browser and display it as a string but have looked everywhere and can't seem to get a value from the XML file.
I need to be able to do this client-side (no server-side scripting)
I am trying to display the current temp etc as a variable
<w:current temperature="13.5" dewPoint="8.5" humidity="72" windSpeed="7.4" windGusts="9.3" windDirection="WSW" pressure="1019.9" rain="1.6" />
My JavaScript code looks like the following:
My XML file:Code:if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET",data,false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; alert(xmlDoc.getElementsByTagName("w:current")[0].childNodes[0].nodeValue);
Code:<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Weather.com.au RSS Feed must be used in accordance with the terms and conditions listed at http://www.weather.com.au/about/rss --> <rss version="2.0" xmlns:w="http://rss.weather.com.au/w.dtd"> <channel> <title>Weather.com.au - Melbourne Weather</title> <link>http://www.weather.com.au/vic/melbourne</link> <description>Current conditions and forecast for Melbourne, Victoria.</description> <language>en-au</language> <copyright>Copyright 2012 - Weather.com.au Pty Ltd</copyright> <pubDate>Sat, 05 May 2012 10:30:00 GMT</pubDate> <lastBuildDate>Sat, 05 May 2012 10:30:00 GMT</lastBuildDate> <ttl>15</ttl> <item> <title>Melbourne Current Conditions</title> <link>http://www.weather.com.au/vic/melbourne/current</link> <description> <![CDATA[ <b>Temperature:</b> 13.5°C<br /> <b>Dew Point:</b> 8.5°C<br /> <b>Relative Humidity:</b> 72%<br /> <b>Wind Speed:</b> 7.4km/h<br /> <b>Wind Gusts:</b> 9.3km/h<br /> <b>Wind Direction:</b> WSW<br /> <b>Pressure:</b> 1019.9hPa<br /> <b>Rain Since 9AM:</b> 1.6mm<br /> ]]> </description> <pubDate>Sat, 05 May 2012 10:30:00 GMT</pubDate> <guid isPermaLink="false">C1336213800</guid> <w:current temperature="13.5" dewPoint="8.5" humidity="72" windSpeed="7.4" windGusts="9.3" windDirection="WSW" pressure="1019.9" rain="1.6" /> </item> <item> <title>Melbourne Forecast</title> <link>http://www.weather.com.au/vic/melbourne</link> <description> <![CDATA[ <p> <b>Sunday:</b><br /> <img src="http://www.weather.com.au/images/icons/4.gif" alt="Partly Cloudy" /><br /> Partly Cloudy. Mild.<br /> 8 - 17<br /> </p> <p> <b>Monday:</b><br /> <img src="http://www.weather.com.au/images/icons/18.gif" alt="Light Rain Early" /><br /> Light Rain Early. Clearing Skies. Mild.<br /> 8 - 17<br /> </p> <p> <b>Tuesday:</b><br /> <img src="http://www.weather.com.au/images/icons/1.gif" alt="Sunny" /><br /> Sunny. Mild.<br /> 10 - 22<br /> </p> ]]> </description> <pubDate>Sat, 05 May 2012 10:30:00 GMT</pubDate> <guid isPermaLink="false">F1336213800</guid> <w:forecast day="Sunday" description="Partly Cloudy. Mild." min="8" max="17" icon="4" iconUri="http://www.weather.com.au/images/icons/4.gif" iconAlt="Partly Cloudy" /> <w:forecast day="Monday" description="Light Rain Early. Clearing Skies. Mild." min="8" max="17" icon="18" iconUri="http://www.weather.com.au/images/icons/18.gif" iconAlt="Light Rain Early" /> <w:forecast day="Tuesday" description="Sunny. Mild." min="10" max="22" icon="1" iconUri="http://www.weather.com.au/images/icons/1.gif" iconAlt="Sunny" /> </item> </channel> </rss>




Reply With Quote