当前位置: 首页 > 网络学院 > XML相关教程 > XML DOM > childNodes 属性

XML DOM
DOM Attribute
DOM Text
DOM CDATA
DOM Comment
DOM HttpRequest
DOM ParseError
DOM 校验器
DOM 介绍
DOM 摘要
DOM 案例
DOM 节点树
DOM 访问节点树
DOM 节点信息
DOM 文档执行
DOM 节点导航

XML DOM 中的 childNodes 属性


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 372 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The childNodes property returns a NodeList of child nodes for the specified node.
childNodes属性的作用是:返回指定节点的字节点列表。

Syntax
语法

nodeObject.childNodes


Tips and Notes
提示

Tip: Use the NodeLists's length property to determine the number of nodes in a node list. When you know the length of a node list, you can easily loop through it and extract the values you want!
提示:使用NodeList[节点列表]length[长度]属性来定义节点列表中的节点数量。当你已经知道了节点列表的长度时,你可以很方便的使用循环语句来提取你想要的值!


In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().
在所有案例中,我们将使用“books.xml”文件以及JavaScript 函数“loadXMLDoc()”。

Example
案例

The following code fragment displays the child nodes of the XML document:
下面的代码片断将显示XML文档中的子节点:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.childNodes;
for (i=0;i<x.length;i++) { document.write("Nodename: " + x[i].nodeName) document.write(" (nodetype: " + x[i].nodeType + ")<br />") }

Output IE:
IE中的输出结果:

Nodename: xml (nodetype: 7)
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)

Output Mozilla (Firefox):
Mozilla(Firefox:火狐)中的输出结果:

Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)


Try-It-Yourself Demos
自我演示

Display the child nodes of the XML document
显示XML文档中的子节点

Display all child nodes of all the elements in the XML document
显示XML文档中所有元素的子节点

评论 (0) All

登陆 | 还没注册?