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 |