Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need help integrating XML file into ASP page

Posted on 2009-02-23
12
Medium Priority
?
342 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:Stephen York
  • 7
  • 5
12 Comments
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 23717966
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
0
 
LVL 1

Author Comment

by:Stephen York
ID: 23720759
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!
0
 
LVL 1

Author Comment

by:Stephen York
ID: 23720784
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:
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Wayne Barron
ID: 23721129
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
0
 
LVL 1

Author Comment

by:Stephen York
ID: 23721263
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!!!!!!!!
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 23721459
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
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 23721468
never mind.
I found it... :)
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 23721661
0
 
LVL 31

Accepted Solution

by:
Wayne Barron earned 2000 total points
ID: 23721851
I did not sleep to well last night, so I am going to nap for a while.
If this is what you are wanting, please download code below
http://www.pcitdad.com/Test/EE/Q_24169421/Q_24169421.zip

Please read the information within' the Q_24169421.asp file
For how everything is working.
Please pay close attention to the ones that are marked as: ' SET DO NOT TOUCH
If you mess around with these values, it will not work properly.

As mentioned above, I am going to take a nap for a while, and will check back if you have
Any concerns about the code.

Worked out pretty sweet.
Have a good one.
Carrzkiss (Wayne)
0
 
LVL 1

Author Comment

by:Stephen York
ID: 23724353
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!
0
 
LVL 1

Author Closing Comment

by:Stephen York
ID: 31550253
OUTSTANDING!
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 23725179
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>.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question