XML DOM Node Types
DOM 將文件表示為一個節點物件的層次結構。
節點型別
下表列出了不同的 W3C 節點型別,以及它們可以擁有的子節點型別
節點型別 | 描述 | 子節點 |
---|---|---|
文件 | 代表整個文件(DOM 樹的根節點) | Element (最多一個)、ProcessingInstruction、Comment、DocumentType |
DocumentFragment | 代表一個“輕量級”的 Document 物件,可以包含文件的一部分 | Element、ProcessingInstruction、Comment、Text、CDATASection、EntityReference |
DocumentType | 提供對文件定義的實體的介面 | 無 |
ProcessingInstruction | 代表一個處理指令 | 無 |
EntityReference | 代表一個實體引用 | Element、ProcessingInstruction、Comment、Text、CDATASection、EntityReference |
元素 | 代表一個元素 | Element、Text、Comment、ProcessingInstruction、CDATASection、EntityReference |
Attr | 代表一個屬性 | Text、EntityReference |
文字 | 代表元素或屬性中的文字內容 | 無 |
CDATASection | 代表文件中的 CDATA 部分(不會被解析器解析的文字) | 無 |
註釋 | 代表一個註釋 | 無 |
實體 | 代表一個實體 | Element、ProcessingInstruction、Comment、Text、CDATASection、EntityReference |
Notation | 代表 DTD 中宣告的一個符號 | 無 |
節點型別 - 返回值
下表列出了每個節點型別的 nodeName 和 nodeValue 屬性將返回什麼
節點型別 | nodeName 返回 | nodeValue 返回 |
---|---|---|
文件 | #document | null |
DocumentFragment | #document fragment | null |
DocumentType | doctype 名稱 | null |
EntityReference | 實體引用名稱 | null |
元素 | 元素名稱 | null |
Attr | 屬性名稱 | 屬性值 |
ProcessingInstruction | target | 節點的內容 |
註釋 | #comment | 註釋文字 |
文字 | #text | 節點的內容 |
CDATASection | #cdata-section | 節點的內容 |
實體 | 實體名稱 | null |
Notation | 符號名稱 | null |
NodeTypes - 命名常量
NodeType | 命名常量 |
---|---|
1 | ELEMENT_NODE |
2 | ATTRIBUTE_NODE |
3 | TEXT_NODE |
4 | CDATA_SECTION_NODE |
5 | ENTITY_REFERENCE_NODE |
6 | ENTITY_NODE |
7 | PROCESSING_INSTRUCTION_NODE |
8 | COMMENT_NODE |
9 | DOCUMENT_NODE |
10 | DOCUMENT_TYPE_NODE |
11 | DOCUMENT_FRAGMENT_NODE |
12 | NOTATION_NODE |