PDA

View Full Version : javascript HTML XMl


Twincpu
15-07-2006, 16:59
Ciao!

Ho relizzato una pagina Html che con un javascript legge un file XML!!! Setto poi le proprietà delle righe e delle colonne della tabella (quella che rispecchia il file xml)!
Ma perchè con Mozzilla me le setta tutte e con Explorer neanche il 10%!
Utilizzo il metodo SetAttribute!

Se volete vedere il codice è questo!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script>
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_ita.xml");
}

function createTable()
{
var x = xmlDoc.getElementsByTagName('articolo');
var newEl = document.createElement('TABLE');
newEl.setAttribute('bgcolor','white');
newEl.setAttribute('width',337);
newEl.setAttribute('style','color: #333; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 19px');
var tmp = document.createElement('TBODY');
newEl.appendChild(tmp);
/*var row = document.createElement('TR');
for (j=0;j<x[0].childNodes.length;j++)
{
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.createElement('TH');
var theData = document.createTextNode(x[0].childNodes[j].nodeName);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);*/
for (i=0;i<x.length;i++)
{
var row = document.createElement('TR');
for (j=0;j<x[i].childNodes.length;j++)
{
if (x[i].childNodes[j].nodeType != 1) continue;
var container = document.createElement('TD');
if( x[0].childNodes[j].nodeName == 'indice')
{
container.setAttribute('valign','top');
container.setAttribute('align','right');
container.setAttribute('style','font-weight:700;color: #c33');
}
var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);
}
document.getElementById('writeroot').appendChild(newEl);
}
</script>

<body onload="importXML()">
<div id="writeroot"></div>
</table>
</body>
</html>