<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>HTML</title>
<script type="text/javascript">
try{
var xmldoc = new ActiveXObject('Microsoft.XMLDOM');
} catch(e){
var xmldoc = document.implementation.createDocument('','',null);
}
xmldoc.async = false;
xmldoc.load('books.xml');
document.write('根元素名称:' + xmldoc.documentElement.nodeName + '<br/><br/>');
var bookEles = xmldoc.getElementsByTagName('book');
for(var i=0;i<bookEles.length;i++){
var bookEle = bookEles[i];
var id = bookEle.getAttribute('id');
var name = bookEle.getElementsByTagName('name')[0].firstChild.nodeValue;
document.write('编号:' + id + ',名称:' + name + '<br/><br/>');
}
</script>
</head>
<body>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>HTML</title>
<script type="text/javascript">
try{
var xmldoc = new ActiveXObject('Microsoft.XMLDOM');
} catch(e){
var xmldoc = document.implementation.createDocument('','',null);
}
xmldoc.async = false;
xmldoc.load('books.xml');
document.write('根元素名称:' + xmldoc.documentElement.nodeName + '<br/><br/>');
var bookEles = xmldoc.getElementsByTagName('book');
for(var i=0;i<bookEles.length;i++){
var bookEle = bookEles[i];
var id = bookEle.getAttribute('id');
var name = bookEle.getElementsByTagName('name')[0].firstChild.nodeValue;
document.write('编号:' + id + ',名称:' + name + '<br/><br/>');
}
</script>
</head>
<body>
</body>
</html>