-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmltable.html
92 lines (88 loc) · 2.58 KB
/
xmltable.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!-- Source: http://ecis.seattleu.edu/lee/5315/jsonxml/xmltable.html -->
<!DOCTYPE html>
<html>
<head>
<!-- load jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<!-- load datatables js library -->
<script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<!-- link datatables css -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">
<script type="text/javascript">
$(document).ready(function(){
var t = $('#chart').DataTable();
$.ajax({
type: "GET",
url: "cd_catalog.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('CD').each(function(){
t.row.add( [
$(this).find('ARTIST').text(),
$(this).find('TITLE').text(),
$(this).find('YEAR').text(),
$(this).find('PRICE').text(),
$(this).find('COMPANY').text(),
$(this).find('COUNTRY').text()
] ).draw( false );
});
}
});
});
</script>
</head>
<body>
<table id="chart" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Artist</th>
<th>Title</th>
<th>Year</th>
<th>Price</th>
<th>Company</th>
<th>Country</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Artist</th>
<th>Title</th>
<th>Year</th>
<th>Price</th>
<th>Company</th>
<th>Country</th>
</tr>
</tfoot>
</table>
</body>
</html>
<!-- ############################ -->
<!-- Written in JavaScript Sample -->
<!-- This is NOT used in the HTML -->
<!-- ############################ -->
<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp);
}
}
xmlhttp.open("GET", "cd_catalog.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Artist</th><th>Title</th></tr>";
var x = xmlDoc.getElementsByTagName("CD");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
</script>