-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml.html
More file actions
41 lines (39 loc) · 1.64 KB
/
xml.html
File metadata and controls
41 lines (39 loc) · 1.64 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function getval(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","student.xml",false);
xmlhttp.send(null);
var xmlText = xmlhttp.responseXML;
// if (window.DOMParser)
// {
// parser=new DOMParser();
// xmlDoc=parser.parseFromString(xmlText,"text/xml");
// }
// else // Internet Explorer
// {
// xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
// xmlDoc.async="false";
// xmlDoc.load("student.xml");
// }
for(var i = 0; i < xmlText.getElementsByTagName("name").length; i++){
document.getElementById("student").innerHTML += "姓名:"+xmlText.getElementsByTagName("name")[i].childNodes[0].nodeValue+"<br/>";
document.getElementById("student").innerHTML += "年龄:"+xmlText.getElementsByTagName("age")[i].childNodes[0].nodeValue+"<br/>";
document.getElementById("student").innerHTML += "学校:"+xmlText.getElementsByTagName("school")[i].childNodes[0].nodeValue+"<br/>";
document.getElementById("student").innerHTML += "<br/>";
}
}
</script>
</head>
<body>
<input type="button" value="提取数据" onclick="getval()" /><br />
<!--<b>姓名:</b> <span id="name"></span><br />-->
<!--<b>年龄:</b> <span id="age"></span><br />-->
<!--<b>学校:</b> <span id="school"></span>-->
<div id="student"></div>
</body>
</html>