XML 节点类型Types of XML Nodes

当将 XML 文档作为节点树读入内存时,这些节点的节点类型在创建节点时确定。When an XML document is read into memory as a tree of nodes, the node types for the nodes are decided when the nodes are created. XML 文档对象模型 (DOM) 具有多种节点类型,这些类型由万维网联合会 (W3C) 确定并在 1.1.1 节“The DOM Structure Model”中列出。The XML Document Object Model (DOM) has several kinds of node types, determined by the World Wide Web Consortium (W3C) and listed in section 1.1.1 The DOM Structure Model. 下表列出了节点类型、分配给该节点类型的对象以及每种节点类型的简短说明。The following table lists the node types, the object assigned to that node type, and a short description of each.

DOM 节点类型DOM node type 对象Object 描述Description
DocumentDocument XmlDocument 树中所有节点的容器。The container of all the nodes in the tree. 它也称作文档根,文档根并非总是与根元素相同。It is also known as the document root, which is not always the same as the root element.
DocumentFragmentDocumentFragment XmlDocumentFragment 包含一个或多个不带任何树结构的节点的临时袋。A temporary bag containing one or more nodes without any tree structure.
DocumentTypeDocumentType XmlDocumentType 表示 <!DOCTYPE…> 节点。Represents the <!DOCTYPE…> node.
EntityReferenceEntityReference XmlEntityReference 表示非扩展的实体引用文本。Represents the non-expanded entity reference text.
元素Element XmlElement 表示元素节点。Represents an element node.
AttrAttr XmlAttribute 为元素的属性。Is an attribute of an element.
ProcessingInstructionProcessingInstruction XmlProcessingInstruction 为处理指令节点。Is a processing instruction node.
注释Comment XmlComment 注释节点。A comment node.
TextText XmlText 属于某个元素或属性的文本。Text belonging to an element or attribute.
CDATASectionCDATASection XmlCDataSection 表示 CDATA。Represents CDATA.
实体Entity XmlEntity 表示 XML 文档(来自内部文档类型定义 (DTD) 子集或来自外部 DTD 和参数实体)中的 <!ENTITY…> 声明。Represents the <!ENTITY…> declarations in an XML document, either from an internal document type definition (DTD) subset or from external DTDs and parameter entities.
NotationNotation XmlNotation 表示 DTD 中声明的表示法。Represents a notation declared in the DTD.

尽管属性 (attr ) 在 W3C DOM 级别 1 的第 1.2 节“基本接口”中作为节点列出,但不能将属性视为任何元素节点的子级。Even though an attribute (attr) is listed in the W3C DOM Level 1 section 1.2 Fundamental Interfaces as a node, it is not considered a child of any element node.

下表列出了 W3C 未定义的其他节点类型,但这些类型可作为 XmlNodeType 枚举在 Microsoft .NET Framework 对象模型中使用。The following table shows additional node types not defined by the W3C, however they are available for use in the Microsoft .NET Framework object model as XmlNodeType enumerations. 因此,这些节点类型不存在匹配的 DOM 节点类型列。Therefore, there is no matching DOM node type column for these node types.

节点类型Node type 描述Description
XmlDeclaration 表示声明节点 <?xml version="1.0"…>Represents the declaration node <?xml version="1.0"…>.
XmlSignificantWhitespace 表示有效空白(混合内容中的空白)。Represents significant white space, which is white space in mixed content.
XmlWhitespace 表示元素内容中的空白。Represents the white space in the content of an element.
EndElementEndElement 当 XmlReader 到达元素末尾时返回。Returned when XmlReader gets to the end of an element.

示例 XML:</item> Example XML: </item>

有关详细信息,请参阅 XmlNodeTypeFor more information, see XmlNodeType.
EndEntityEndEntity 当 XmlReader 由于 ResolveEntity 调用而到达实体替换的末尾时返回。Returned when XmlReader gets to the end of the entity replacement as a result of a call to ResolveEntity. 有关详细信息,请参阅 XmlNodeTypeFor more information, see XmlNodeType.

若要查看读取 XML 并对节点类型使用 case 构造以打印节点及其内容相关信息的代码示例,请参阅 NodeTypeTo view a code example that reads in XML and uses a case construct on the node types to print information about the node and its contents, see NodeType.

若要详细了解节点类型及对应的相当对象名称的对象层次结构,请参阅 XML 文档对象模型 (DOM) 层次结构For more information on the object hierarchy of the node types and their equivalent object name, see XML Document Object Model (DOM) Hierarchy. 若要详细了解在节点树中创建的对象,请参阅将对象层次结构映射到 XML 数据For more information on the objects created in the node tree, see Mapping the Object Hierarchy to XML Data.

请参阅See also