-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml-Str.html
More file actions
37 lines (37 loc) · 1.12 KB
/
xml-Str.html
File metadata and controls
37 lines (37 loc) · 1.12 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
txt="<bookstore><book>";
txt=txt+"<title>Everyday Italian</title>";
txt=txt+"<author>Giada De Laurentiis</author>";
txt=txt+"<year>2005</year>";
txt=txt+"</book></bookstore>";
// <bookstore>
// <book>
// <title>Everyday Italian</title>
// <author>Giada De Laurentiis</author>
// <year>2005</year>
// </book>
// </bookstore>
if (window.DOMParser)
{
parser=new DOMParser();
var xmlDoc=parser.parseFromString(txt,"text/xml");
alert(xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue);
}
else // Internet Explorer
{
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(txt);
alert(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue);
}
</script>
</head>
<body>
<input type="text" id="aa"/>
</body>
</html>