PDA

View Full Version : Javascript e XML Problema


Twincpu
18-07-2006, 23:13
Ciao!
Ho realizzatto un javascript che mi legge un file xml ma ora nn mi funziona pių in internet explorer! Con mozzilla invece funziona tutto perfettamente!
Prima funzionava in entrambe i browser ma il codice č lo stesso! Vi lascio il codice javascript!

function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createTable;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) createTable()
};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("articolo.xml");
}

function createTable()
{
var x = xmlDoc.getElementsByTagName('articolo');
var newEl = document.createElement('TABLE');
newEl.setAttribute('id','art');
var tmp = document.createElement('TBODY');
newEl.appendChild(tmp);
for (i=0;i<x.length;i++)
{
var row = document.createElement('TR');
for (j=0;j<(x[i].childNodes.length)-2;j++)
{
if (x[i].childNodes[j].nodeType != 1) continue;
var container = document.createElement('TD');
if( x[0].childNodes[j].nodeName == 'indice')
container.setAttribute('id','ind');
else
container.setAttribute('id','test');
var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);
}
document.getElementById('writeroot2').appendChild(newEl);
}

Eccolo!
Ho provato a mettere un alert prima di " for (i=0;i<x.length;i++) "
e appare! l'ho messo appena dentro il for e non appare pių in internet explorer!

Aiutatemi!