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

XML DOM
DOM 节点
DOM 节点列表
DOM 解析
DOM 遍历节点树
DOM Mozilla 和 IE
DOM 获取节点
DOM 设置节点
DOM 删除节点
DOM 更换节点
DOM 建立节点
DOM 添加节点
DOM 克隆节点
DOM 节点类型
DOM Node
DOM NodeList
DOM NamedNodeMap
DOM Document
DOM DocumentType
DOM ProcessingInstr
DOM Element

XML DOM 中的 childNodes 属性


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 371 ::
收藏到网摘: 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

登陆 | 还没注册?