...

View Full Version : XML loading (Internet Explorer & Firefox)



sosuke
03-16-2005, 06:56 PM
Arg, this works perfectly in Firefox, but in Internet Explorer it errors out as "Object Required" in this line:

build = x[0].childNodes[3].childNodes[1].childNodes[1].firstChild.nodeValue;

<script>
function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = getBuild;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) getBuild()
};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("/SystemService/getSystemInfo");
}
function getBuild()
{
var x = xmlDoc.getElementsByTagName('Something');

build = x[0].childNodes[3].childNodes[1].childNodes[1].firstChild.nodeValue;
build = build.slice(6, 10);
var newEl = document.createTextNode(build);
document.getElementById('build').appendChild(newEl);

var x = xmlDoc.getElementsByTagName('SomethingElse');

hostname = x[0].childNodes[3].firstChild.nodeValue;
var newEl = document.createTextNode(hostname);
document.getElementById('hostname').appendChild(newEl);
}
</script>Can someone help me figure out whats going wrong here? Thanks! :thumbsup:

sosuke
03-16-2005, 07:34 PM
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")

nodes=xmlDoc.documentElement.childNodes
a1.innerText=nodes.item(0).text
a2.innerText=nodes.item(1).text
a3.innerText=nodes.item(2).text
a4.innerText=nodes.item(3).texthttp://www.w3schools.com/xml/tryit.asp?filename=note
this works for IE, but not Firefox!

codegoboom
03-16-2005, 10:39 PM
There are a couple working examples archived here... (search this & the xml forum); and about the error, you can narrow it down by checking for 'typeof', starting with the object and tacking on each reference, until you get undefined, or something.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum