have to query five attributes from a site. I have the following code but it is n
ID: 3541846 • Letter: H
Question
have to query five attributes from a site. I have the following code but it is not working. Please help me. I am stuck
>
<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal" cfi:lastdownloaderr
or="None">
<html>
> <head>
> <script>
> function loadXMLDoc()
> {
> //Build up a mock XML response from our server
> window.xmlResponse = "<?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet href="latest_ob.xsl" type="text/xsl"?>
> <current_observation version="1.0"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http://www.weather.gov/view/current_observation.xsd">
> <credit>NOAA's National Weather Service</credit>
> <credit_URL>http://weather.gov/</credit_URL>
> <image><url>http://www.nhc.noaa.gov/gifs/xml_logo_nhc.gif</url><title>NHC Weather Service - No current storm</title><link>http://www.nhc.noaa.gov/</link><width>95</width><height>45</height><description>NOAA logo</description></image>
>
cf:type="html"<suggested_pickupxmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">15 minutes after the hour</suggested_pickup>
> <suggested_pickup_period>60</suggested_pickup_period>
> <location>Salt Lake City International, UT</location>
> <station_id>KSLC</station_id>
> <latitude>40.79</latitude>
> <longitude>-111.97</longitude>
> <observation_time>Last Updated on Sep 13 2013, 12:53 pm MDT</observation_time>
> <observation_time_rfc822>Fri, 13 Sep 2013 12:53:00 -0600</observation_time_rfc822>
> <weather>Thunderstorm</weather>
> <temperature_string>67.0 F (19.4 C)</temperature_string>
> <temp_f>67.0</temp_f>
> <temp_c>19.4</temp_c>
> <relative_humidity>68</relative_humidity>
> <wind_string>Northwest at 15.0 MPH (13 KT)</wind_string>
> <wind_dir>Northwest</wind_dir>
> <wind_degrees>310</wind_degrees>
> <wind_mph>15.0</wind_mph>
> <wind_kt>13</wind_kt>
> <pressure_string>1010.9 mb</pressure_string>
> <pressure_mb>1010.9</pressure_mb>
> <pressure_in>29.99</pressure_in>
> <dewpoint_string>55.9 F (13.3 C)</dewpoint_string>
> <dewpoint_f>55.9</dewpoint_f>
> <dewpoint_c>13.3</dewpoint_c>
> <visibility_mi>10.00</visibility_mi>
> <icon_url_base>http://forecast.weather.gov/images/wtf/small/</icon_url_base>
> <two_day_history_url>http://www.weather.gov/data/obhistory/KSLC.html</two_day_history_url>
> <icon_url_name>tsra.png</icon_url_name>
> <ob_url>http://www.weather.gov/data/METAR/KSLC.1.txt</ob_url>
> <disclaimer_url>http://weather.gov/disclaimer.html</disclaimer_url>
> <copyright_url>http://weather.gov/disclaimer.html</copyright_url>
> <privacy_policy_url>http://weather.gov/notice.html</privacy_policy_url>
> </current_observation>";
>
>
> var parser;
> //Load the XML into the DOM
> if (window.DOMParser)
> {
> parser=new DOMParser();
> xmlDoc=parser.parseFromString(window.xmlResponse,"text/xml");
> }
> else // Internet Explorer
> {
> xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
> xmlDoc.async=false;
> xmlDoc.loadXML(window.xmlResponse);
> }
> //Get the wind string from the response XML
> var location = xmlDoc.getElementsByTagName("location")[0].childNodes[0].nodeValue;
> var weather = xmlDoc.getElementsByTagName("weather")[0].childNodes[0].nodeValue;
> var temperature_string = xmlDoc.getElementsByTagName("temperature_string")[0].childNodes[0].nodeValue;
> var wind_string = xmlDoc.getElementsByTagName("wind_string")[0].childNodes[0].nodeValue;
> var visibility_mi = xmlDoc.getElementsByTagName("visibility_mi")[0].childNodes[0].nodeValue;
> //Get the element
> document.getElementById("location").innerHTML = location;
> document.getElementById("weather").innerHTML = weather;
> document.getElementById("temperature_string").innerHTML = temperature_string;
> document.getElementById("wind_string").innerHTML = wind_string;
> document.getElementById("visibility_mi").innerHTML = visibility_mi;
>
> }
> </script>
> </head>
> <body>
>
> <div id="myDiv">
> <table>
> <tr>
> <th>Location</th>
> <th>Weather</th>
> <th>Temperature</th>
> <th>Wind</th>
> <th>Visibility</th>
> </tr>
> <tr>
> <td id="location"></td>
> <td id="weather"></td>
> <td id="temperature_string"></td>
> <td id="wind_string"></td>
> <td id="visibility_mi"></td>
> </tr>
> </table>
> </div>
> <button type="button">Change Content</button>
>
>
>
> </body></html>
</xml>
Explanation / Answer
Here is a relatively sophisticated RSS document that uses these common namespaces:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<channel>
<title>My weblog</title>
<link>http://www.example.com/</link>
<description>My cute tagline</description>
<dc:language>en-us</dc:language>
<dc:creator>Me (me@example.com)</dc:creator>
<dc:rights>Copyright 2002 Me</dc:rights>
<dc:date>2002-10-18T16:10:15-05:00</dc:date>
<admin:generatorAgent rdf:resource="http://www.movabletype.org/?v=2.5" />
<admin:errorReportsTo rdf:resource="mailto:me@example.com"/>
<item>
<title>Take up knitting</title>
<link>http://www.example.com/archives/000054.html</link>
<description>Hidden Mozilla preferences. XSLT tips. Transcript of the Eldred case.</description>
<content:encoded><![CDATA[<ul>
<li><a href="http://www.geocities.com/pratiksolanki/">Hidden Mozilla prefs</a>.</li>
<li><a href="http://www.perfectxml.com/TipsXSLT.asp">50 XSLT tips</a>. [via <a href="http://simon.incutio.com/">Simon</a>]</li>
<li><a href="http://www.aaronsw.com/2002/eldredTranscript">Transcript of the Eldred Supreme Court case</a>. Converted to HTML and publicly archived by <a href="http://www.aaronsw.com/weblog/">Aaron</a>.</li>
</ul>]]></content:encoded>
<dc:subject>Miscellaneous</dc:subject>
<dc:date>2002-10-18T16:10:15-05:00</dc:date>
</item>
</channel>
</rss>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.