XML DOM nodeType 属性
定义和用法
nodeType 属性返回被选节点的节点类型。
语法:
elementNode.nodeType
| 节点编号: | 节点名称: | 
|---|---|
| 1 | Element | 
| 2 | Attribute | 
| 3 | Text | 
| 4 | CDATA Section | 
| 5 | Entity Reference | 
| 6 | Entity | 
| 7 | Processing Instrucion | 
| 8 | Comment | 
| 9 | Document | 
| 10 | Document Type | 
| 11 | Document Fragment | 
| 12 | Notation | 
实例
在所有的例子中,我们将使用 XML 文件 books.xml,以及 JavaScript 函数 loadXMLDoc()。
下面的代码片段获取 "books.xml" 的第一个 <title> 元素的节点类型:
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0];
document.write(x.nodeType);
以上代码的输出:
1

