XmlNode.ParentNode 属性

定义

获取该节点的父级(针对可以拥有父级的节点)。Gets the parent of this node (for nodes that can have parents).

public:
 virtual property System::Xml::XmlNode ^ ParentNode { System::Xml::XmlNode ^ get(); };
public virtual System.Xml.XmlNode ParentNode { get; }
public virtual System.Xml.XmlNode? ParentNode { get; }
member this.ParentNode : System.Xml.XmlNode
Public Overridable ReadOnly Property ParentNode As XmlNode

属性值

XmlNode

作为当前节点父级的 XmlNodeThe XmlNode that is the parent of the current node. 如果刚刚创建了一个节点且尚未将其添加到树中,或如果已从树中移除了该节点,则父级为 nullIf a node has just been created and not yet added to the tree, or if it has been removed from the tree, the parent is null. 对于所有其他节点,返回的值取决于节点的 NodeTypeFor all other nodes, the value returned depends on the NodeType of the node. 下表描述了 ParentNode 属性可能的返回值。The following table describes the possible return values for the ParentNode property.

NodeTypeNodeType ParentNode 的返回值Return Value of ParentNode
Attribute、Document、DocumentFragment、Entity、NotationAttribute, Document, DocumentFragment, Entity, Notation 返回 null;这些节点不具有父级。Returns null; these nodes do not have parents.
CDATACDATA 返回包含 CDATA 节的元素或实体引用。Returns the element or entity reference containing the CDATA section.
评论Comment 返回包含注释的元素、实体引用、文档类型或文档。Returns the element, entity reference, document type, or document containing the comment.
DocumentTypeDocumentType 返回文档节点。Returns the document node.
元素Element 返回该元素的父节点。Returns the parent node of the element. 如果该元素是树中的根节点,则父级是文档节点。If the element is the root node in the tree, the parent is the document node.
EntityReferenceEntityReference 返回包含该实体引用的元素、特性或实体引用。Returns the element, attribute, or entity reference containing the entity reference.
ProcessingInstructionProcessingInstruction 返回包含该处理指令的文档、元素、文档类型或实体引用。Returns the document, element, document type, or entity reference containing the processing instruction.
文本Text 返回包含该文本节点的父元素、特性或实体引用。Returns the parent element, attribute, or entity reference containing the text node.

注解

有关父节点和子节点的信息,请参阅 W3C DOM (Core) Level 1 规范For information about parent and child nodes, see the W3C DOM (Core) Level 1 specification

适用于