Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading a Weather Channel XML

Status
Not open for further replies.

mikemedia

Programmer
Apr 28, 2006
39
US
Am trying the SDK that The Weather Channel offers, but I can't seem to even access the URL other than in a browser.
Suggestions?

Here's what I've done so far within the <head>:

<script type="text/javascript">
var xmlDoc = new ActiveXobject ("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("[1026000259]&key=[8860efa025e505c3]");
document.write(xmlDoc);
document.write("xml.doc.weather.head");
document.write(xmlDoc.getElementsByTagName("loc"));
</script>
 
I don't know the mentioned sdk. But, I would be surprised it contains something to the effect of what you've posted. There are a few issues.

[1] The url seems need some urlencoding to function properly.
[2] document.write (xmlDoc) is no good, no good at all.
[3] document.write (xmlDoc.getElementsByTagName("loc") is a collection or an error. It is no good at all to document.write it.

There are some other technical refined problems notably this.
[4] Your loading url contain some querystring. I would be surprised if the synchroneous loading will ever succeed. You should do it, and maybe you can only successfully do it, asynchronously.

This is a page that will succeed. You can expand or abridge it. In any case, tailor to your need.
[tt]
<html>
<head>
<script type="text/javascript">
var xmlDoc;
function x() {
xmlDoc=new ActiveXObject ("Msxml2.domDocument");
xmlDoc.async=true;
xmlDoc.validateOnParse=false;
xmlDoc.onreadystatechange=y;
var surl=" //contains urlencoded characters
}
function y() {
if (xmlDoc.readyState==4) {
document.getElementById("divid").innerHTML="xml.doc.weather.head<br />"+xmlDoc.getElementsByTagName("loc")[0].text;
var s=xmlDoc.xml;
s=s.replace(/>/g,"&gt;");
s=s.replace(/</g,"&lt;");
document.getElementById("divid2").innerHTML="<pre>"+s+"</pre>";
}
}
window.onload=x;
</script>
</head>
<body>
<div id="divid"></div>
<div id="divid2"></div>
</body>
</html>
[/tt]
Now you have something to get on with.
 
Amendment

I forgot to script the loading line into it. It is here...
[tt]
function x() {
xmlDoc=new ActiveXObject ("Msxml2.domDocument");
xmlDoc.async=true;
xmlDoc.validateOnParse=false;
xmlDoc.onreadystatechange=y;
var surl=" //contains urlencoded characters
[blue]xmlDoc.load (surl);[/blue]
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top