-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentxml.html
52 lines (47 loc) · 1.79 KB
/
studentxml.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
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8" />
<title>Student database</title>
<style>
table,th,td {
border : 2px solid black;
border-collapse: collapse ;
}
th,td {
padding: 5px;
}
</style>
</head>
<body>
<button type="button" onclick="studentData()">Click Here</button>
<table id="students-list"></table>
<script>
function studentData(){
var std = new XMLHttpRequest();
std.onreadystatechange = function(){
if(this.readyState==4 && this.status==200){
myFunction(this);
}
}
std.open("GET","stddata.xml",true);
std.send();
};
function myFunction(xml){
var i
var xmlDoc = xml.responseXML;
var table = "<tr><th>Name</th><th>USN</th><th>Branch</th><th>Year Admitted</th><th>Address</th></tr>";
var doc = xmlDoc.getElementById("student");
for (i=0; i<doc.length; i++){
table+="<tr><td>"+
doc[i].getElementByTagname("name")[0].childnode[0].nodevalue[0]+"</td><td>"+
doc[i].getElementByTagname("usn")[0].childnode[0].nodevalue[0]+"</td><td>"+
doc[i].getElementByTagname("branch")[0].childnode[0].nodevalue[0]+"</td><td>"+
doc[i].getElementByTagname("year")[0].childnode[0].nodevalue[0]+"</td><td>"+
doc[i].getElementByTagname("address")[0].childnode[0].nodevalue[0]+"</td></tr>"
}
document.getElementById("students-list").innerHTML=table;
}
</script>
</body>
</html>