XML DOM 节点类型

  • 节点类型

    下表列出了不同的W3C节点类型,以及它们可能作为子级的节点类型:
    节点类型 描述 子级节点
    Document 表示整个文档(DOM树的根节点) Element(最多1个),ProcessingInstruction,Comment,DocumentType
    DocumentFragment 表示一个 “轻量级” Document对象,该对象可以保存文档的一部分 Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
    DocumentType 提供到为文档定义的实体的接口 无
    ProcessingInstruction 代表加工指令 无
    EntityReference 代表实体参考 Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
    Element 代表一个元素 Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
    Attr 代表一个属性 Text, EntityReference
    Text 表示元素中的文本内容或属性 无
    CDATASection 表示文档中的CDATA部分(无法由解析器解析) 无
    Comment 代表评论 无
    Entity 代表实体 Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
    Notation 表示在DTD中声明的符号 无
  • 节点类型-返回值

    下表列出了每种节点类型的 nodeName 和 nodeValue 属性将返回的内容:
    节点类型 nodeName 返回 nodeValue 返回
    Document #document null
    DocumentFragment #document fragment null
    DocumentType doctype name null
    EntityReference entity reference name null
    Element element name null
    Attr attribute name attribute value
    ProcessingInstruction target content of node
    Comment #comment comment text
    Text #text content of node
    CDATASection #cdata-section content of node
    Entity entity name null
    Notation notation name null
  • 节点类型-命名常量

    下表列出了每种节点类型的 nodeName 和 nodeValue 属性将返回的内容:
    节点类型 命名常量
    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