Jump to content

Display elements of XML file in a table.


thebl
 Share

Recommended Posts

I've been able so far to display XML elements on the users screen as follows using the spantag. Although to make it more appealing, I've trying to get the following in a table format. If anyone can help me, it would be much appreciated!!

function getData(){	if ((xHRObject.readyState == 4) &&(xHRObject.status == 200))	{		var serverResponse = xHRObject.responseXML;		var header = serverResponse.getElementsByTagName("AuctionItem");		var spantag = document.getElementById("ack");		setTimeout("showAuction('ack')", 10000);		spantag.innerHTML = "";		for (i=0; i<header.length; i++)		{		   		if (window.ActiveXObject)		{			 spantag.innerHTML += " " +header[i].childNodes[0].text;			 spantag.innerHTML += " " +header[i].childNodes[1].text;			 spantag.innerHTML += " " +header[i].childNodes[2].text;			 spantag.innerHTML += " " +header[i].childNodes[3].text;			 spantag.innerHTML += " " +header[i].childNodes[4].text;			 spantag.innerHTML += " " +header[i].childNodes[5].text;			 spantag.innerHTML += " " +header[i].childNodes[6].text;			 spantag.innerHTML += " " +header[i].childNodes[7].text;			 spantag.innerHTML += " " +header[i].childNodes[8].text;			 spantag.innerHTML += " " +header[i].childNodes[9].text;			 spantag.innerHTML += " " +header[i].childNodes[10].text;			 spantag.innerHTML += " " +header[i].childNodes[11].text;			 //spantag.innerHTML += " " +header[i].firstChild.text;			 spantag.innerHTML += " <br />";		}		else		{			 spantag.innerHTML += " " +header[i].childNodes[0].textContent;			 spantag.innerHTML += " " +header[i].childNodes[1].textContent;			 spantag.innerHTML += " " +header[i].childNodes[2].textContent;			 spantag.innerHTML += " " +header[i].childNodes[3].textContent;			 spantag.innerHTML += " " +header[i].childNodes[4].textContent;			 spantag.innerHTML += " " +header[i].childNodes[5].textContent;			 spantag.innerHTML += " " +header[i].childNodes[6].textContent;			 spantag.innerHTML += " " +header[i].childNodes[7].textContent;			 spantag.innerHTML += " " +header[i].childNodes[8].textContent;			 spantag.innerHTML += " " +header[i].childNodes[9].textContent;			 spantag.innerHTML += " " +header[i].childNodes[10].textContent;			 spantag.innerHTML += " " +header[i].childNodes[11].textContent;			 //spantag.innerHTML += " " +header[i].firstChild.textContent;			 spantag.innerHTML += " <br />";		}	   }	}}

Link to comment
Share on other sites

I'm aware of two ways to dynamically build a table using javascript.1)

var html = "<table border='1'>";html += "<tr>";html += "<td>Hello</td><td>World</td>";html += "</tr>";html += "</table>";document.getElementById("MyDisplayDiv").innerHTML = html;

2)

var table = document.createElement("table");table.border = "1";var tr = document.createElement("tr");var td1 = document.createElement("td");td1.appendChild(document.createTextNode("Hello"));var td2 = document.createElement("td");td2.appendChild(document.createTextNode("World"));tr.appendChild(td1);tr.appendChild(td2);table.appendChild(tr);document.getElementById("MyDisplayDiv").appendChild(table);

Link to comment
Share on other sites

I've never used "insertRow" nor "insertCell", but it appears like that should work just fine. What happens when you execute the code? Are there any error messages in the javascript console?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...