XmlNode XmlNode XmlNode XmlNode Class

定义

表示 XML 文档中的单个节点。Represents a single node in the XML document.

public ref class XmlNode abstract : ICloneable, System::Collections::IEnumerable, System::Xml::XPath::IXPathNavigable
public abstract class XmlNode : ICloneable, System.Collections.IEnumerable, System.Xml.XPath.IXPathNavigable
type XmlNode = class
    interface ICloneable
    interface IEnumerable
    interface IXPathNavigable
Public MustInherit Class XmlNode
Implements ICloneable, IEnumerable, IXPathNavigable
继承
XmlNodeXmlNodeXmlNodeXmlNode
派生
实现

注解

此类实现 W3C 文档对象模型(DOM)级别1核心和核心 DOM 级别2。This class implements the W3C Document Object Model (DOM) Level 1 Core and the Core DOM Level 2. DOM 是 XML 文档的内存中(缓存)树表示形式。The DOM is an in-memory (cache) tree representation of an XML document. XmlNode是 DOM 的 .NET 实现中的基类。XmlNode is the base class in the .NET implementation of the DOM. 它支持 XPath 选择并提供编辑功能。It supports XPath selections and provides editing capabilities. XmlDocument类扩展XmlNode并表示 XML 文档。The XmlDocument class extends XmlNode and represents an XML document. 可以使用XmlDocument加载和保存 XML 数据。You can use XmlDocument to load and save XML data. 它还包括用于节点创建的方法。It also includes methods for node creation. 有关详细信息,请参阅XML 文档对象模型(DOM)See XML Document Object Model (DOM) for more information.

重要

由于使用XmlNode类而引发的异常,例如XmlException类可能包含不应在不受信任的方案中公开的敏感信息。Exceptions raised as a result of using the XmlNode class, such as the XmlException class may contain sensitive information that should not be exposed in untrusted scenarios. 应正确处理异常,以便不受信任的情况下不公开此敏感信息。Exceptions should be properly handled so that this sensitive information is not exposed in untrusted scenarios.

属性

Attributes Attributes Attributes Attributes

获取一个 XmlAttributeCollection,它包含该节点的特性。Gets an XmlAttributeCollection containing the attributes of this node.

BaseURI BaseURI BaseURI BaseURI

获取当前节点的基 URI。Gets the base URI of the current node.

ChildNodes ChildNodes ChildNodes ChildNodes

获取节点的所有子节点。Gets all the child nodes of the node.

FirstChild FirstChild FirstChild FirstChild

获取节点的第一个子级。Gets the first child of the node.

HasChildNodes HasChildNodes HasChildNodes HasChildNodes

获取一个值,该值指示此节点是否有任何子节点。Gets a value indicating whether this node has any child nodes.

InnerText InnerText InnerText InnerText

获取或设置节点及其所有子节点的串连值。Gets or sets the concatenated values of the node and all its child nodes.

InnerXml InnerXml InnerXml InnerXml

获取或设置仅表示该节点的子节点的标记。Gets or sets the markup representing only the child nodes of this node.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取指示节点是否只读的值。Gets a value indicating whether the node is read-only.

Item[String, String] Item[String, String] Item[String, String] Item[String, String]

获取具有指定 LocalNameNamespaceURI 的第一个子元素。Gets the first child element with the specified LocalName and NamespaceURI.

Item[String] Item[String] Item[String] Item[String]

获取具有指定 Name 的第一个子元素。Gets the first child element with the specified Name.

LastChild LastChild LastChild LastChild

获取节点的最后一个子级。Gets the last child of the node.

LocalName LocalName LocalName LocalName

当在派生类中被重写时,获取节点的本地名称。Gets the local name of the node, when overridden in a derived class.

Name Name Name Name

当在派生类中被重写时,获取节点的限定名称。Gets the qualified name of the node, when overridden in a derived class.

NamespaceURI NamespaceURI NamespaceURI NamespaceURI

获取该节点的命名空间 URI。Gets the namespace URI of this node.

NextSibling NextSibling NextSibling NextSibling

获取紧接在该节点之后的节点。Gets the node immediately following this node.

NodeType NodeType NodeType NodeType

当在派生类中被重写时,获取当前节点的类型。Gets the type of the current node, when overridden in a derived class.

OuterXml OuterXml OuterXml OuterXml

获取包含此节点及其所有子节点的标记。Gets the markup containing this node and all its child nodes.

OwnerDocument OwnerDocument OwnerDocument OwnerDocument

获取此节点所属的 XmlDocumentGets the XmlDocument to which this node belongs.

ParentNode ParentNode ParentNode ParentNode

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

Prefix Prefix Prefix Prefix

获取或设置该节点的命名空间前缀。Gets or sets the namespace prefix of this node.

PreviousSibling PreviousSibling PreviousSibling PreviousSibling

获取紧接在该节点之前的节点。Gets the node immediately preceding this node.

PreviousText PreviousText PreviousText PreviousText

获取紧接在该节点之前的文本节点。Gets the text node that immediately precedes this node.

SchemaInfo SchemaInfo SchemaInfo SchemaInfo

获取作为架构验证的结果分配给此节点的后架构验证信息集。Gets the post schema validation infoset that has been assigned to this node as a result of schema validation.

Value Value Value Value

获取或设置节点的值。Gets or sets the value of the node.

方法

AppendChild(XmlNode) AppendChild(XmlNode) AppendChild(XmlNode) AppendChild(XmlNode)

将指定的节点添加到该节点的子节点列表的末尾。Adds the specified node to the end of the list of child nodes, of this node.

Clone() Clone() Clone() Clone()

创建此节点的副本。Creates a duplicate of this node.

CloneNode(Boolean) CloneNode(Boolean) CloneNode(Boolean) CloneNode(Boolean)

当在派生类中被重写时,创建该节点的副本。Creates a duplicate of the node, when overridden in a derived class.

CreateNavigator() CreateNavigator() CreateNavigator() CreateNavigator()

创建 XPathNavigator 以浏览此对象。Creates an XPathNavigator for navigating this object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

获取循环访问当前节点中子节点的枚举数。Gets an enumerator that iterates through the child nodes in the current node.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetNamespaceOfPrefix(String) GetNamespaceOfPrefix(String) GetNamespaceOfPrefix(String) GetNamespaceOfPrefix(String)

查找当前节点范围内离给定的前缀最近的 xmlns 声明,并返回声明中的命名空间 URI。Looks up the closest xmlns declaration for the given prefix that is in scope for the current node and returns the namespace URI in the declaration.

GetPrefixOfNamespace(String) GetPrefixOfNamespace(String) GetPrefixOfNamespace(String) GetPrefixOfNamespace(String)

查找当前节点范围内离给定的命名空间 URI 最近的 xmlns 声明,并返回声明中定义的前缀。Looks up the closest xmlns declaration for the given namespace URI that is in scope for the current node and returns the prefix defined in that declaration.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InsertAfter(XmlNode, XmlNode) InsertAfter(XmlNode, XmlNode) InsertAfter(XmlNode, XmlNode) InsertAfter(XmlNode, XmlNode)

将指定的节点紧接着插入指定的引用节点之后。Inserts the specified node immediately after the specified reference node.

InsertBefore(XmlNode, XmlNode) InsertBefore(XmlNode, XmlNode) InsertBefore(XmlNode, XmlNode) InsertBefore(XmlNode, XmlNode)

将指定的节点紧接着插入指定的引用节点之前。Inserts the specified node immediately before the specified reference node.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Normalize() Normalize() Normalize() Normalize()

将此 XmlNode 下子树完全深度中的所有 XmlText 节点都转换成“正常”形式,在这种形式中只有标记(即标记、注释、处理指令、CDATA 节和实体引用)分隔 XmlText 节点,也就是说,没有相邻的 XmlText 节点。Puts all XmlText nodes in the full depth of the sub-tree underneath this XmlNode into a "normal" form where only markup (that is, tags, comments, processing instructions, CDATA sections, and entity references) separates XmlText nodes, that is, there are no adjacent XmlText nodes.

PrependChild(XmlNode) PrependChild(XmlNode) PrependChild(XmlNode) PrependChild(XmlNode)

将指定的节点添加到该节点的子节点列表的开头。Adds the specified node to the beginning of the list of child nodes for this node.

RemoveAll() RemoveAll() RemoveAll() RemoveAll()

移除当前节点的所有子节点和/或属性。Removes all the child nodes and/or attributes of the current node.

RemoveChild(XmlNode) RemoveChild(XmlNode) RemoveChild(XmlNode) RemoveChild(XmlNode)

移除指定的子节点。Removes specified child node.

ReplaceChild(XmlNode, XmlNode) ReplaceChild(XmlNode, XmlNode) ReplaceChild(XmlNode, XmlNode) ReplaceChild(XmlNode, XmlNode)

oldChild 节点替换子节点 newChildReplaces the child node oldChild with newChild node.

SelectNodes(String) SelectNodes(String) SelectNodes(String) SelectNodes(String)

选择匹配 XPath 表达式的节点列表。Selects a list of nodes matching the XPath expression.

SelectNodes(String, XmlNamespaceManager) SelectNodes(String, XmlNamespaceManager) SelectNodes(String, XmlNamespaceManager) SelectNodes(String, XmlNamespaceManager)

选择匹配 XPath 表达式的节点列表。Selects a list of nodes matching the XPath expression. XPath 表达式中的任何前缀都使用提供的 XmlNamespaceManager 进行解析。Any prefixes found in the XPath expression are resolved using the supplied XmlNamespaceManager.

SelectSingleNode(String) SelectSingleNode(String) SelectSingleNode(String) SelectSingleNode(String)

选择匹配 XPath 表达式的第一个 XmlNodeSelects the first XmlNode that matches the XPath expression.

SelectSingleNode(String, XmlNamespaceManager) SelectSingleNode(String, XmlNamespaceManager) SelectSingleNode(String, XmlNamespaceManager) SelectSingleNode(String, XmlNamespaceManager)

选择匹配 XPath 表达式的第一个 XmlNodeSelects the first XmlNode that matches the XPath expression. XPath 表达式中的任何前缀都使用提供的 XmlNamespaceManager 进行解析。Any prefixes found in the XPath expression are resolved using the supplied XmlNamespaceManager.

Supports(String, String) Supports(String, String) Supports(String, String) Supports(String, String)

测试 DOM 实现是否实现特定的功能。Tests if the DOM implementation implements a specific feature.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
WriteContentTo(XmlWriter) WriteContentTo(XmlWriter) WriteContentTo(XmlWriter) WriteContentTo(XmlWriter)

当在派生类中被重写时,该节点的所有子节点会保存到指定的 XmlWriter 中。Saves all the child nodes of the node to the specified XmlWriter, when overridden in a derived class.

WriteTo(XmlWriter) WriteTo(XmlWriter) WriteTo(XmlWriter) WriteTo(XmlWriter)

当在派生类中被重写时,将当前节点保存到指定的 XmlWriter 中。Saves the current node to the specified XmlWriter, when overridden in a derived class.

显式界面实现

ICloneable.Clone() ICloneable.Clone() ICloneable.Clone() ICloneable.Clone()

有关此成员的说明,请参见 Clone()For a description of this member, see Clone().

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

有关此成员的说明,请参见 GetEnumerator()For a description of this member, see GetEnumerator().

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

CreateNavigator(XmlNode) CreateNavigator(XmlNode) CreateNavigator(XmlNode) CreateNavigator(XmlNode)
SelectNodes(XmlNode, String) SelectNodes(XmlNode, String) SelectNodes(XmlNode, String) SelectNodes(XmlNode, String)
SelectNodes(XmlNode, String, XmlNamespaceManager) SelectNodes(XmlNode, String, XmlNamespaceManager) SelectNodes(XmlNode, String, XmlNamespaceManager) SelectNodes(XmlNode, String, XmlNamespaceManager)
SelectSingleNode(XmlNode, String) SelectSingleNode(XmlNode, String) SelectSingleNode(XmlNode, String) SelectSingleNode(XmlNode, String)
SelectSingleNode(XmlNode, String, XmlNamespaceManager) SelectSingleNode(XmlNode, String, XmlNamespaceManager) SelectSingleNode(XmlNode, String, XmlNamespaceManager) SelectSingleNode(XmlNode, String, XmlNamespaceManager)
ToXPathNavigable(XmlNode) ToXPathNavigable(XmlNode) ToXPathNavigable(XmlNode) ToXPathNavigable(XmlNode)

适用于

另请参阅