thebl Posted September 20, 2007 Share Posted September 20, 2007 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 More sharing options...
jesh Posted September 20, 2007 Share Posted September 20, 2007 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 More sharing options...
thebl Posted September 20, 2007 Author Share Posted September 20, 2007 The thing is I've already found a way of displaying the the XML elements in a table format, using the following code. I draw the table with onLoad="init('XML/auction.xml') and display in the <tbody id="biddingData"> Link to comment Share on other sites More sharing options...
jesh Posted September 21, 2007 Share Posted September 21, 2007 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 More sharing options...
thebl Posted September 21, 2007 Author Share Posted September 21, 2007 It displays the elements perfectly and it works how I want it to work! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.