XML DOM childNodes 属性
Document 对象
定义和用法
childNodes 属性返回文档的子节点的节点列表。
语法
documentObject.childNodes
提示和注释
提示: 请使用 NodeList 的长度属性来测定节点列表中的节点数量。在您知道节点列表的长度后,就能够轻易地循环遍历此节点列表,并提取您需要的值!
实例
下面的代码片段使用 loadXMLDoc() 把 " books.xml " 载入 xmlDoc 中,并显示 XML 文档的子节点:
实例
xmlDoc
=
loadXMLDoc
(
"
books.xml
"
)
;
x
=
xmlDoc
.
childNodes
;
for
(
i
=
;
i
<
x
.
length
;
i
++
)
{
document
.
write
(
"
Nodename:
"
+
x
[
i
]
.
nodeName
+
"
<br>
"
)
;
document
.
write
(
"
(nodetype:
"
+
x
[
i
]
.
nodeType
+
"
)
"
)
;
}
输出 IE:
Nodename: xml (nodetype: 7)
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)
输出 Mozilla (Firefox):
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)
Nodename: bookstore (nodetype: 1)
尝试一下 »
尝试一下 Demos
Document 对象