Displaying XML tree structure with DOM

wxdqz

New Member
I created this html file to display the tree structure of an external xml file. However, it displays "#text" next to the name or value. How do i get rid of that?

--------------------------------------------------------------XHTML CODE

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>XML Data Traversal</title>
<style type="text/css">body {
background-color: #999999;
}
</style>
<script language="JavaScript">


var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");



function loadXML(xmlFile) {
xmlDoc.async="false";
xmlDoc.onreadystatechange=verify;
xmlDoc.load(xmlFile);
}

function verify() {
if(xmlDoc.readyState!=4)
return false;
}

function traverse(tree) {
document.writeln (tree.nodeName);

if(tree.hasChildNodes()) {
document.writeln('<ul><li>');
var nodes=tree.childNodes.length;
for(var i=0; i<tree.childNodes.length; i++)
{
traverse(tree.childNodes.item(i));
}
document.write('</li></ul>');
}
else
document.write(tree.text);
}


function initTraverse(file) {
loadXML(file);
var doc=xmlDoc.documentElement;
traverse(doc);

}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>


<br>
<table width="500" align="center"><tr><td>


<font face="courier">
<script language="JavaScript">
initTraverse("assignment8.xml");
</script>
</font>
</td></tr></table>

</body>
</html>

--------------------------------------------------EXAMPLE OF RESULT
nba
statistic
name
#text Allen Iverson
games
#text 5
fieldgoals
#text 59
freethrows
#text 26
points
#text 156
pointspergame
#text 31.2
 
Back
Top