XML DOM childNodes 属性
Node 对象
定义和用法
childNodes 属性返回指定节点的子节点的节点列表。
语法
nodeObject.childNodes
提示和注释
提示: 请使用节点列表的 length 属性来计算一个节点列表中节点的数目。当您已经知道节点列表的长度后,您就可以轻松地循环遍历此列表,并提取您所需要的值!
实例
下面的代码片段使用 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
Node 对象