Problem displaying table from xml in explorer

U

uyireh

Hi,
I am trying to read some data from an xml file and display it in a
webpage. I am facing 2 problems.

1) I can't seem to display the table in explorer. It works fine with
mozilla.

2) I also want to display the alternating rows in different colors. I
have a CSS file where I have specified different colors for different
rows eg. <tr class="spec"...and <tr class="specalt"...
But this doesn't seem to work when I use javascript to read the xml
file and display it in a table form.

Please advise what I should do. The javascript code is attached below.

--------------
readxml.js
--------------
function importXML(xmlfilename)
{
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(xmlfilename);
}

function createTable()
{
var x = xmlDoc.getElementsByTagName('sentence');
var newEl = document.createElement('TABLE');
newEl.setAttribute('cellPadding',5);

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.childNodes.length;j++)
{
if (x.childNodes[j].nodeType != 1) continue;
var container = document.createElement('TD');
var theData =
document.createTextNode(x.childNodes[j].firstChild.nodeValue);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);
}
document.getElementById('writeroot').appendChild(newEl);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top