...

View Full Version : XML DOM and Tables



Forever Zero
07-01-2008, 10:00 PM
Hey all,

I am trying to make a little test page (using the digg API) that basically just lists all of the attributes of each <digg> tag in a table.

All of the attributes list fine, except the text will not go inside table cells.

Here is the page in action so you can see what I mean:
http://foreverzero.org/GWT/diggtest.html
NOTE: This only works in Firefox for the time being.

Here is the XML is outputs:
http://services.digg.com/stories/diggs?appkey=http&#37;3A%2F%2Fapidoc.digg.com

Here is the code:


<html>

<head>
<title> Digg API Test </title>
<script type="text/javascript">
// Function to load an XML DOM from a string of XML
function loadXMLString(txt) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(txt,"text/xml");
return(xmlDoc);
}
</script>
</head>

<body onload="doAjax('http://services.digg.com/stories/diggs?appkey=http%3A%2F%2Fapidoc.digg.com');">

<script type="text/javascript">
// Function to load up the XML and then pass it to loadXMLString with responseText
function doAjax(url) {
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange=function() {
// What to do once the XML responseText string has been loaded
if (xmlHttp.readyState == 4) {
// Load up an XML DOM
xmlDoc = loadXMLString(xmlHttp.responseText);
document.getElementById("myDiv").innerHTML = "<table border=1 cellpadding=4><tr><td>Date:</td><td>Story:</td><td>ID:</td><td>User:</td><td>Status:</td></tr>";
// Date, Story, ID, User, Status
diggsArray = xmlDoc.getElementsByTagName("digg");
// For each <digg /> element...
for (var i = 0; i < diggsArray.length; i++) {
document.getElementById("myDiv").innerHTML += "<tr>";
// Get a list of attributes from this <digg /> element
currentAttributes = diggsArray[i].attributes;
// Set variables for readability
var date = currentAttributes.getNamedItem("date").value;
var story = currentAttributes.getNamedItem("story").value;
var id = currentAttributes.getNamedItem("id").value;
var user = currentAttributes.getNamedItem("user").value;
var status = currentAttributes.getNamedItem("status").value;
// Put information inside cells
document.getElementById("myDiv").innerHTML += "<td>"+date+"</td>";
document.getElementById("myDiv").innerHTML += "<td>"+story+"</td>";
document.getElementById("myDiv").innerHTML += "<td>"+id+"</td>";
document.getElementById("myDiv").innerHTML += "<td>"+user+"</td>";
document.getElementById("myDiv").innerHTML += "<td>"+status+"</td>";
document.getElementById("myDiv").innerHTML += "</tr>";
} // for
document.getElementById("myDiv").innerHTML += "</table>";
} // if
} // function
xmlHttp.open("GET","php_proxy_simple.php?yws_path="+url,true);
xmlHttp.send(null);
}
</script>

<div id="myDiv">
This should change.
</div>

</body>

</html>


The data is all printed out, but none of it has <td> or <tr> tags wrapped around it.

You can see in this separate page that the data does indeed import correctly, it just won;t apply td or tr tags.
http://foreverzero.org/GWT/diggtest3.html

Any help would be much appreciated :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum