I’m just learning how to parse an XML feed with JavaScript, but I’m having some problems. If I copy and paste the code from the XML feed into an internal file, and I reference that file in my code, it works fine. But when I try to change the XML source doc to the XML feed’s URL ([url]http://codeamber.org/a1xl04act/amberalert.xml)
[code]<%@LANGUAGE=”JAVASCRIPT” %>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Pull XML Feed</title>
<script type=”text/javascript”>
var xmlDoc;
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async=false;
xmlDoc.load(“pullxmlfeed.xml”);//I want this to pull from external XML feed at http://codeamber.org/a1xl04act/amberalert.xml
getmessage();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument(“”,””,null);
xmlDoc.load(“pullxmlfeed.xml”);//I want this to pull from external XML feed at http://codeamber.org/a1xl04act/amberalert.xml
xmlDoc.onload=getmessage;
}
else
{
alert(‘Your browser cannot handle this script’);
}
}
function getmessage()
{
document.getElementById(“Alertstatus”).innerHTML=xmlDoc.getElementsByTagName(“Alertstatus”)[0].childNodes[0].nodeValue;
document.getElementById(“FullText”).innerHTML=xmlDoc.getElementsByTagName(“FullText”)[0].childNodes[0].nodeValue;
document.getElementById(“Alertinfo”).innerHTML=xmlDoc.getElementsByTagName(“Alertinfo”)[0].childNodes[0].nodeValue;
document.getElementById(“AlertState”).innerHTML=Alertinfo.getElementsByTagName(“states”)[0].childNodes[0].nodeValue;//I want to pull attribute ‘status’ from ‘Alertinfo’ node
document.getElementById(“Victim”).innerHTML=xmlDoc.getElementsByTagName(“Victim”)[0].childNodes[0].nodeValue;
}
</script>
</head>
<body onload=”loadXML()”>
<h1>Pull XML Feed</h1>
<p><b>Alertstatus:</b> <span id=”Alertstatus”></span><br />
<b>FullText:</b> <span id=”FullText”></span><br />
<b>Alertinfo:</b> <span id=”Alertinfo”></span><br />
<b>AlertState:</b> <span id=”AlertState”></span><br />
<b>Victim:</b> <span id=”Victim”></span>
</p>
</body>
</html>