This is the XML file that needs to be parsed, we will call it "servers.xml". This file is on the same server I want it parsed (xml file in same folder).
<root>
<list>
<server>
<server name="28 Disconnects Later">
<timestamp name="2015-02-25 14:28:56">low</timestamp>
<timestamp name="2015-02-25 14:58:56">low</timestamp>
<timestamp name="2015-02-25 15:28:57">low</timestamp>
<timestamp name="2015-02-25 15:58:58">low</timestamp>
<timestamp name="2015-02-25 16:28:59">low</timestamp>
<timestamp name="2015-02-25 16:59:00">low</timestamp>
<timestamp name="2015-02-25 17:29:01">low</timestamp>
<timestamp name="2015-02-25 17:59:02">low</timestamp>
<timestamp name="2015-02-25 18:29:04">low</timestamp>
<timestamp name="2015-02-25 18:59:05">low</timestamp>
</server>
<server name="Abomination">
<timestamp name="2015-02-25 14:28:56">high</timestamp>
<timestamp name="2015-02-25 14:58:56">high</timestamp>
<timestamp name="2015-02-25 15:28:57">high</timestamp>
<timestamp name="2015-02-25 15:58:58">high</timestamp>
<timestamp name="2015-02-25 16:28:59">high</timestamp>
<timestamp name="2015-02-25 16:59:00">high</timestamp>
<timestamp name="2015-02-25 17:29:01">high</timestamp>
<timestamp name="2015-02-25 17:59:02">high</timestamp>
<timestamp name="2015-02-25 18:29:04">high</timestamp>
<timestamp name="2015-02-25 18:59:05">high</timestamp>
</server>
</server>
</list>
</root>
I need to sort it into a table like so:
|----------------------------------|
| server name |
|----------------------------------|
| timestamp name | timestamp value |
| timestamp name | timestamp value |
| timestamp name | timestamp value |
| timestamp name | timestamp value |
| timestamp name | timestamp value |
|----------------------------------|
| |
|----------------------------------|
| server name |
|----------------------------------|
| timestamp name | timestamp value |
| timestamp name | timestamp value |
| timestamp name | timestamp value |
| timestamp name | timestamp value |
| timestamp name | timestamp value |
I have been working on how todo this for a couple of hours but can't seem to get stuff to display correctly or at all.
Any help is appreciated
EDIT CURRENT CODE:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse:collapse;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","AOD-H1Z1.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table><tr><th colspan='2'>Server</th></tr>");
var x=xmlDoc.getElementsByTagName("server");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("timestamp")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("timestamp")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>