Link to home
Start Free TrialLog in
Avatar of Jay Newcome
Jay NewcomeFlag for United States of America

asked on

Need help integrating XML file into ASP page

I would like to include weather data on our school website using XML from weather service and then just show and tell the information (I do not want to use the plugins from places such as the Weather Channel as they contain adds and other uselessware).   I am running IIS6.

I can copy the XML file to my local domain but I can not get my ASP pages to read the XML file and display the data.  I am showing the code that I am using in the ASP page below and have attached the XML file from the weather service.  I am sure that this is not really all that tough, but I do not know a ton about using ASP... Adding insult to injury, this works on my local PC when I do a HTTP to the weather service, but not when I do the local referenced XML file or when I try to run on my IIS server...  I am not wed to the code, I found it on-line.  If you have a better way and I can follow it, I will.

In addition, if you can help me, how do Iink the two different elements together so that I can load the weather graphic referenced in the XML file?

I really appreciate the help!!!
<html>
<head>
<-- Determine how to parse the XML and then load the XML file elements-->
<script type="text/javascript">
function parseXML()
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e)
    {
    alert(e.message);
    return;
    }
  }
xmlDoc.async=false;
xmlDoc.load("KAKR.xml");
 
document.getElementById("observation_time").innerHTML=xmlDoc.getElementsByTagName("observation_time")[0].childNodes[0].nodeValue;
document.getElementById("temperature_string").innerHTML=xmlDoc.getElementsByTagName("temperature_string")[0].childNodes[0].nodeValue;
document.getElementById("windchill_string").innerHTML=xmlDoc.getElementsByTagName("windchill_string")[0].childNodes[0].nodeValue;
document.getElementById("weather").innerHTML=xmlDoc.getElementsByTagName("weather")[0].childNodes[0].nodeValue;
document.getElementById("relative_humidity").innerHTML=xmlDoc.getElementsByTagName("relative_humidity")[0].childNodes[0].nodeValue;
document.getElementById("wind_string").innerHTML=xmlDoc.getElementsByTagName("wind_string")[0].childNodes[0].nodeValue;
document.getElementById("pressure_string").innerHTML=xmlDoc.getElementsByTagName("pressure_string")[0].childNodes[0].nodeValue;
document.getElementById("dewpoint_string").innerHTML=xmlDoc.getElementsByTagName("dewpoint_string")[0].childNodes[0].nodeValue;
document.getElementById("heat_index_string").innerHTML=xmlDoc.getElementsByTagName("heat_index_string")[0].childNodes[0].nodeValue;
document.getElementById("icon_url_base").innerHTML=xmlDoc.getElementsByTagName("icon_url_base")[0].childNodes[0].nodeValue;
document.getElementById("icon_url_name").innerHTML=xmlDoc.getElementsByTagName("icon_url_name")[0].childNodes[0].nodeValue;
}
</script>
</head>
 
<body onload="parseXML()">
 
<-- Display the weather statistics for the students -->
<h2>Current Weather</h2>
 
<p><b>Conditions:</b> <span id="weather"></span><br />
<b>Current Temperature:</b> <span id="temperature_string"></span><br />
<b>Wind Chill:</b> <span id="windchill_string"></span><br />
<p><b>Heat Index:</b> <span id="heat_index_string"></span></p>
 
<b>Wind:</b> <span id="wind_string"></span><br />
<b>Relative Humidity:</b> <span id="relative_humidity"></span>%<br />
<b>Barometer:</b> <span id="pressure_string"></span><br />
<b>Dewpoint:</b> <span id="dewpoint_string"></span><br />
 
<-- build the img tag to load the weather icon - Currently not working... -->
<img src="<span id="icon_url_base"></span><span id="icon_url_name"></span>"><p>
 
<p><b>Updated:</b> <span id="observation_time"></span><br />
 
</p>
</body>
</html>

Open in new window

KCAK.txt
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Is this the actual feed from the Weather site?
The one thing that has me stuck, is that this:
      <image>
            <url>http://weather.gov/images/xml_logo.gif</url>
            <title>NOAA's National Weather Service</title>
            <link>http://weather.gov</link>
      </image>

I am having a hard time getting this to parse correctly through the page.
I cannot do juse   <url>  (For the Image) as it picks up on another element.

Also.
Let me know exactly how you would like to have this laid out?
Do you want to use up all the elements that are available?
Or do you just want to use specific ones?

Carrzkiss
Avatar of Jay Newcome

ASKER

Hi - This XML is an actual feed (http://www.weather.gov/xml/current_obs/KCAK.xml ).  They update it every hour or sometimes sooner, but I download the XML file to my server once an hour to protect some of our WAN bandwidth (I don't want all 1500 of our machines hitting the weather websiote every time somebody opens a browser window).  l am just going to display 90% of the contents in a simple text table or even as simply as a list with the BR tag- really nothing fancy.  I was thinking of using a virtual include so that I could code once, use often... I just want to display a quick snapshot as to what is going on to help the buildings decide about recess, and for the science kids to get a quick data picture for tracking weather when they do their weather sections (plus it is kind of cool to show the local weather data).  

The image thing was messing with me too as I am not up enough on VBScript to programaticy combine the elements.  To be honest, the image is the least of my needs, what I really need is to be able to show the data on one of my ASP pages.  

To get a slightly better idea as to how the XML and the real data work together, the original XML feed is: http://www.weather.gov/xml/current_obs/KCAK.xml and the web page that the NWS uses to show and tell is: http://forecast.weather.gov/MapClick.php?CityName=Ravenna&state=OH&site=CLE&textField1=41.1598&textField2=-81.2426&e=0.  

I hope to buy one of those local weather stations for our district in a year or two, but this will suffice until I can afford that.  Thanx for the help - I really do appreciate it!
Sorry, as I reread your question, I realize I may not have properly answered it...  Here is what I am looking for out of the data.  I would most likely want to have the heading be a STRONG tag but otherwise, everything else would be plain text.  I listed these elements in the ASP code that I placed initially if that helps any.

Current Weather
Conditions:
Current Temperature:
Wind Chill:
Heat Index:

Wind:
Relative Humidity: %
Barometer:
Dewpoint:

Weather updated:
OK
I will look in on this here in a few.
Thanks for the opertunity to do this for you as well.
As this was something that I was trying to do back many years ago.
But within a program designed in "Delphi".
This is the first time that I have done it in ASP.

I will have something for you in a little while.
Also.
If you have a paticular layout that you would like to provide code for,
That will make it a lot nicer on the presentation outcome.

Thanks
Carrzkiss
COOL!  Actually, I will be setting it into a DIV and we are working on the background colors later this morning (we are doing a total redsign of our website) so the text and the background can be whatever default.  I can make the change to the text elements.  As for the layout, if it looked like my last entry, that would be awesome.

THANX AGAIN!!!!!!!!
What is this? And where is it in the XML file?
<p><b>Conditions:</b> <span id="weather"></span><br />
There is no Element called: weather
never mind.
I found it... :)
ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx Wayne B!  I tested this out and it works - VERY COOL!!!!  Is there anyway to include the code within the HEAD section rather than outside of it?  I just ask so that I could include it in my virtual includes that I use for my standard menus, CSS,...

I really appreciate your work!
OUTSTANDING!
Yes.
Add the HTML part where ever you wish for it to be at.
And then take the ASP part and at it as:
<!--#include file="WeatherXML.asp"-->
To the TOP of the <head>

Everything will work like a charm.

Also.
I do not know if you read my profile or not.
But I am working on my Resume. (You do not have to provide information if you do not want to)
So. if you can read the part of my profile about the Resume part, and if you agree.
Then you can contact me via the e-mail address provided on my profile.
If not, no problem at all.

Have a good one.
And add the ASP part to the <head>.