XML DOM 節點類型
DOM 是一個代表節點對象層次的文檔。

嘗試一下 - 實例
下麵的實例使用 XML 檔 books.xml。
函數 loadXMLDoc(),位於外部 JavaScript 中,用於加載 XML 檔。
節點類型
下麵的表格列舉了不同的 W3C 節點類型,每個節點類型中可能會包含子類:
節點類型 | 描述 | 子類 |
---|---|---|
Document | 代表整個文檔(DOM 樹的根節點) | Element (max. one), ProcessingInstruction, Comment, DocumentType |
DocumentFragment | 代表"羽量級"的 Document 對象,它可以保留文檔中的一部分 | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity參考手冊 |
DocumentType | 為文檔中定義的實體提供了一個介面 | None |
ProcessingInstruction | 代表一個處理指令 | None |
EntityReference | 代表一個實體引用 | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference |
Element | 表示一個元素 | Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference |
Attr | 代表一個屬性 | Text, EntityReference |
Text | 代表元素或屬性的文本內容 | None |
CDATASection | 代表文檔中的 CDATA 區段(文本不會被解析器解析) | None |
Comment | 代表一個注釋 | None |
Entity | 代表一個實體 | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference |
Notation | 定義一個在 DTD 中聲明的符號 | None |
節點類型 - 返回值
下麵的表格列舉了每個節點類型(nodetype)所返回的節點名稱(nodeName)和節點值(nodeValue):
節點類型 | 返回的節點名稱 | 返回的節點值 |
---|---|---|
Document | #document | null |
DocumentFragment | #document fragment | null |
DocumentType | 文檔類型名稱 | null |
Entity參考手冊 | 實體引用名稱 | null |
Element | 元素名稱 | null |
Attr | 屬性名稱 | 屬性值 |
ProcessingInstruction | 目標 | 節點的內容 |
Comment | #comment | 注釋文本 |
Text | #text | 節點的內容 |
CDATASection | #cdata-section | 節點的內容 |
Entity | 實體名稱 | null |
Notation | 符號名稱 | null |
節點類型 - 命名常量
節點類型 | 命名常量 |
---|---|
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 |