当前位置: 首页 > 网络学院 > 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   浏览: 364 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The childNodes property returns a NodeList of child nodes for the document.
childNodes属性的作用是:返回文档子节点的节点列表。

Syntax
语法

documentObject.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)

评论 (0) All

登陆 | 还没注册?