XML DOM nodeType 属性
❮ 元素对象
示例
以下代码片段将 "books.xml" 加载到 xmlDoc 中,并获取第一个 <title> 元素的节点类型
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("title")[0];
document.getElementById("demo").innerHTML =
x.nodeType;
}
上面代码的输出将是
1
自己动手试一试 »
定义和用法
nodeType 属性返回所选节点的节点类型。
语法
elementNode.nodeType| 节点类型 | 节点名称 |
|---|---|
| 1 | 元素 |
| 2 | Attribute |
| 3 | 文本 |
| 4 | CDATA Section |
| 5 | Entity Reference |
| 6 | 实体 |
| 7 | Processing Instruction |
| 8 | 注释 |
| 9 | 文档 |
| 10 | Document Type |
| 11 | Document Fragment |
| 12 | Notation |
实际操作演示
❮ 元素对象