joshbates15
Technical User
I'm so close to figuring this out, but I need a little help with the looping to get my data. What I'm having problems with is putting the data from the XML tags "<saying>" into a list.
The XML file looks like this...
This is the code from my html/javascript...
any help or suggestions would be very welcomed! Thanks!
The XML file looks like this...
Code:
<?xml version="1.0" encoding="UTF-8"?>
<aaronsays>
<date>June 15, 2005</date>
<saying>If he was Catholic, I would be his godfather.</saying>
<saying>Tell everyone I'm the reigning champ!</saying>
<saying>I think my mom stole my clothes.</saying>
</aaronsays>
This is the code from my html/javascript...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head>
<title>Aaron Says</title>
<style type="text/css">
.date {display:block;}
</style>
<script type="text/javascript">
var xmlDoc;
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{
xmlDoc = new XMLHttpRequest();
xmlDoc.onreadystatechange = processXMLChange;
xmlDoc.open("GET", "content.xml", true);
xmlDoc.send(null);
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlDoc)
{
xmlDoc.onreadystatechange = processXMLChange;
xmlDoc.open("GET", "content.xml", true);
xmlDoc.send();
}
}
}
function processXMLChange()
{
if (xmlDoc.readyState == 4)
{
if (xmlDoc.status == 200)
{
document.getElementById("content").innerHTML = "";
var aaronSays = xmlDoc.responseXML.documentElement;
var xmlDate = aaronSays.getElementsByTagName("date")[0].firstChild.data;
var xmlSaying = aaronSays.getElementsByTagName("saying");
[red]var listSaying = document.createElement("ul");[/red]
[red]for (i=0;i<xmlSaying.length;i++)[/red]
[red]{[/red]
[red] var container = document.createElement("li");[/red]
[red]var sayingElm = xmlSaying[i];[/red]
[red]var theData = document.createTextNode(sayingElm.firstChild.nodeValue);[/red]
[red]container.appendChild(theData);[/red]
[red]}[/red]
[red]listSaying.appendChild(container);[/red]
[red]var div = document.getElementById("content").innerHTML = "<span>"+xmlDate+"</span><br />"+listSaying;[/red]
}
else
{
alert("Error reading XML Data, please be patient while we fix the problem");
window.location="[URL unfurl="true"]http://aaronsays.com"[/URL]
}
}
}
</script>
</head>
<body onload="loadXMLDoc()">
<div id="header">Header</div>
<div id="content"></div>
<div id="footer">Footer</div>
</body>
</html>
any help or suggestions would be very welcomed! Thanks!