<html xmlns="http://www.w3.org/1999/xhtml">
<
head
>
<
title
>
程鹏测试
</
title
>
<
script
type
="text/javascript"
language
="javascript">
//
载入
XML
文档
function
loadXMLFILE
() {
var
oXmlDom
=
createXMLDOM
();
oXmlDom
.
async
=
false
;
oXmlDom
.
load
(
"cp.xml"
);
var
items
=
oXmlDom
.
getElementsByTagName
(
"test"
);
for
(
var
i
= 0;
i
<
items
.
length
;
i
++) {
var
childs
=
items
[
i
].
childNodes
;
if
(
childs
!=
null
) {
for
(
var
j
= 0;
j
<
childs
.
length
;
j
++) {
alert
(
childs
[
j
].
firstChild
.
nodeValue
);
}
}
}
}
//
创建
DOM
对象
function
createXMLDOM
() {
var
arrSignatures
= [
"MSXML2.DOMDocument.5.0"
,
"MSXML2.DOMDocument.4.0"
,
"MSXML2.DOMDocument.3.0"
,
"MSXML2.DOMDocument"
,
"Microsoft.XmlDom"
];
for
(
var
i
= 0;
i
<
arrSignatures
.
length
;
i
++) {
try
{
var
oXmlDom
=
new
ActiveXObject
(
arrSignatures
[
i
]);
return
oXmlDom
;
}
catch
(
oError
) {
document
.
write
(
oError
.
message
);
}
throw
new
Error
(
"MSXML is not installed on your system."
);
}
}
</
script
>
</
head
>
<
body
>
<
input
type
="button"
value
="
循环弹出
XML
节点的值
"
onclick
="loadXMLFILE()"
/>
</
body
>
</
html
>
cp.xml文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<test>
<a>x1</a>
<b>x2</b>
</test>