booklist_d.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<booklist name="English">
<book1>
<name>Ajax</name>
<price>$5.95</price>
<description>Foundations of Ajax.</description>
</book1>
<book2>
<name>Ajax Patterns</name>
<price>$7.95</price>
<description>Introduction of Ajax Patterns.</description>
</book2>
<book3>
<name>Ajax Web App</name>
<price>$8.95</price>
<description>Edition 2.</description>
</book3>
<book4>
<name>Core CSS</name>
<price>$4.50</price>
<description>A book for CSS.</description>
</book4>
<book5>
<name>JSF and Ajax</name>
<price>$6.95</price>
<description>Apress.</description>
</book5>
</booklist>
JavaScript代码:
function createDocument()

...{
var aVersions = [
"MSXML2.DOMDocument.5.0",
"MSXML2.DOMDocument.4.0",
"MSXML2.DOMDocument.3.0",
"MSXML2.DOMDocument",
"Microsoft.XmlDom"];
for(var i=0;i < aVersions.length;i++)

...{

try...{
var XmlDoc = new ActiveXObject(aVersions[i]);
return XmlDoc;
}

catch(oError)...{}
}
throw new Error("MSXML is not installed");
}
var xmlDom = createDocument();
xmlDom.async = "false";
xmlDom.load("booklist_d.xml");
document.write("该文档的根节点为:" + xmlDom.documentElement.nodeName + "<br/>");
document.write("根节点的属性列表为:" + xmlDom.documentElement.attributes.getNamedItem("name").nodeValue + "<br/>");
document.write("根节点子节点列表为:" + xmlDom.documentElement.childNodes[0].childNodes[0].nodeValue + "<br/>");
document.write("book1节点的父节点为:" + xmlDom.documentElement.childNodes[0].parentNode.nodeName + "<br/>");
document.write("book1节点name的nodeValue为:" + xmlDom.documentElement.childNodes[0].childNodes[0].childNodes[0].nodeValue + "<br/>");
document.write("book3节点的上一节点为:" + xmlDom.documentElement.childNodes[2].previousSibling.nodeName + "<br/>");
document.write("book3节点的下一节点为:" + xmlDom.documentElement.childNodes[2].nextSibling.nodeName + "<br/>");
document.write("根节点下第一个子节点为:" + xmlDom.documentElement.firstChild.nodeName + "<br/>");
document.write("根节点下最后一个子节点为:" + xmlDom.documentElement.lastChild.nodeName + "<br/>");
document.write("xmlDom对象的doctype:" + xmlDom.doctype + "<br/>");
运行结果如下:
该文档的根节点为:booklist
根节点的属性列表为:English
根节点子节点列表为:null
book1节点的父节点为:booklist
book1节点name的nodeValue为:Ajax
book3节点的上一节点为:book2
book3节点的下一节点为:book4
根节点下第一个子节点为:book1
根节点下最后一个子节点为:book5
xmlDom对象的doctype:null































































该文档的根节点为:booklist
根节点的属性列表为:English
根节点子节点列表为:null
book1节点的父节点为:booklist
book1节点name的nodeValue为:Ajax
book3节点的上一节点为:book2
book3节点的下一节点为:book4
根节点下第一个子节点为:book1
根节点下最后一个子节点为:book5
xmlDom对象的doctype:null