XML DOM 節點類型

DOM 將文檔呈現為節點對象的層次結構。

節點類型

下面的表格列出了不同的 W3C 節點類型,以及它們可擁有的子元素:

節點類型 描述 子元素
Document 表示整個文檔(DOM 樹的根節點)
  • Element (max. one)
  • ProcessingInstruction
  • Comment
  • DocumentType
DocumentFragment 表示輕量級的 Document 對象,其中容納了一部分文檔。
  • ProcessingInstruction
  • Comment
  • Text
  • CDATASection
  • EntityReference
DocumentType 向為文檔定義的實體提供接口。 None
ProcessingInstruction 表示處理指令。 None
EntityReference 表示實體引用元素。
  • ProcessingInstruction
  • Comment
  • Text
  • CDATASection
  • EntityReference
Element 表示 element(元素)元素
  • Text
  • Comment
  • ProcessingInstruction
  • CDATASection
  • EntityReference
Attr 表示屬性。
  • Text
  • EntityReference
Text 表示元素或屬性中的文本內容。 None
CDATASection 表示文檔中的 CDATA 區段(文本不會被解析器解析) None
Comment 表示注釋。 None
Entity 表示實體。
  • ProcessingInstruction
  • Comment
  • Text
  • CDATASection
  • EntityReference
Notation 表示在 DTD 中聲明的符號。 None

節點類型 - 所返回的值

下面的表格列出了對每個節點類型來說,nodeName 和 nodeValue 屬性可返回的值:

節點類型 nodeName 的返回值 nodeValue 的返回值
Document #document null
DocumentFragment #document fragment null
DocumentType doctype 名稱 null
EntityReference 實體引用名稱 null
Element element name null
Attr 屬性名稱 屬性值
ProcessingInstruction target 節點的內容
Comment #comment 注釋文本
Text #text 節點內容
CDATASection #cdata-section 節點內容
Entity 實體名稱 null
Notation 符號名稱 null

NodeTypes - 有名常數

NodeType Named Constant
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