XML DOM nodeType 屬性
Element 對象
定義和用法
nodeType 屬性返回選定節點的節點類型。
語法
elementNode.nodeType
| 節點數量: | 節點名稱: |
|---|---|
| 1 | Element |
| 2 | Attribute |
| 3 | Text |
| 4 | CDATA Section |
| 5 | Entity Reference |
| 6 | Entity |
| 7 | Processing Instruction |
| 8 | Comment |
| 9 | Document |
| 10 | Document Type |
| 11 | Document Fragment |
| 12 | Notation |
實例
下麵的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,並從第一個 <title> 元素取得節點類型:
實例
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0];
document.write(x.nodeType);
x=xmlDoc.getElementsByTagName("title")[0];
document.write(x.nodeType);
上面的代碼將輸出:
1
嘗試一下
Element 對象
