-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDOMPars.html
67 lines (56 loc) · 1.95 KB
/
DOMPars.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
<html>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<body>
<style>
table, th, td {
border: 2px solid black;
border-collapse: collapse;
}
th
{
font-size: 25px;
background-color: #d15485;
box-shadow: 0 0 15px 0;
}
td{
padding: 5px;
font-size: 14.5px;
border-radius: 50px;
background: #d6efc7;
box-shadow: 0 0 10px 0;
}
</style>
<script type="text/javascript">
var xmlFile = 'https://sandhya-margabandhu.github.io/xmlfile1/DOMPars.xml';
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", xmlFile, true);
xhttp.send();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
xmlFunction(this.response);
}
};
}
function xmlFunction(xml) {
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xml, "text/xml");
var table = "<tr><th>Cafe Name</th><th>Address</th><th>Timings</th><th>Review</th><th>Price</th><th>Order</th><th>Contact</th></tr>"; //subcategory heading
var x = xmlDoc.getElementsByTagName("CAFEDETAILS");
for (var elem of x) {
var name = elem.getElementsByTagName("NAME")[0].childNodes[0].nodeValue;
var address = elem.getElementsByTagName("ADDRESS")[0].childNodes[0].nodeValue;
var timings = elem.getElementsByTagName("TIMINGS")[0].childNodes[0].nodeValue;
var review = elem.getElementsByTagName("REVIEW")[0].childNodes[0].nodeValue;
var price = elem.getElementsByTagName("PRICE")[0].childNodes[0].nodeValue;
var order = elem.getElementsByTagName("ORDER")[0].childNodes[0].nodeValue;
var contact = elem.getElementsByTagName("CONTACT")[0].childNodes[0].nodeValue;
table += "<tr><td>" + name + "</td><td>" + address + "</td><td>" + timings +"</td><td>"+review+"</td><td>"+price+ "</td> <td>" + order + "</td><td>" + contact + "</td></tr>";
}
document.getElementById("myTable").innerHTML = table;
}
loadDoc();
</script>
<table id="myTable"></table>
</body>
</html>