XText 类

定义

表示文本节点。Represents a text node.

public ref class XText : System::Xml::Linq::XNode
public class XText : System.Xml.Linq.XNode
type XText = class
    inherit XNode
Public Class XText
Inherits XNode
继承
派生

注解

XML 元素可以包含文本内容。XML elements can contain text content. 有时内容很简单(元素只包含文本内容),有时内容会混合(元素的内容同时包含文本和其他元素)。Sometimes the content is simple (the element only contains text content), and sometimes the content is mixed (the contents of the element contains both text and other elements). 在任一情况下,文本块都表示为 XText 节点。In either case, each chunk of text is represented as an XText node.

LINQ to XMLLINQ to XML 开发人员通常需要编写代码来处理它们未创建的任意 LINQ to XMLLINQ to XML 树。developers will often have to write code to work with arbitrary LINQ to XMLLINQ to XML trees that they did not create. 如果要编写的代码必须与无法控制创建的 LINQ to XMLLINQ to XML 树一起使用,则应注意 XText 节点的某些行为。If you are writing code that has to work with LINQ to XMLLINQ to XML trees that you have no control over creating, you should be aware of certain behaviors of XText nodes.

在节点级别处理 XML 树的内容时,应准备好多个 XText 节点彼此相邻。When processing the contents of an XML tree at the node level, you should be prepared for multiple XText nodes to be adjacent to each other. 此外,应准备好 XText 不包含任何文本的节点。Further, you should be prepared for XText nodes that contain no text. 可以通过 LINQ to XMLLINQ to XML 方法删除文本节点的内容。It is possible through LINQ to XMLLINQ to XML methods to remove the content of a text node. LINQ to XMLLINQ to XML 不会自动删除节点。However, LINQ to XMLLINQ to XML does not automatically delete the node. 节点具有标识并且可能具有批注,因此 LINQ to XMLLINQ to XML 允许在树中使用长度为零的节点。The node has identity, and might have annotations, so LINQ to XMLLINQ to XML allows for zero-length nodes in the tree.

有关详细信息,请参阅对节点进行编程For more information, see Programming with Nodes.

构造函数

XText(String)

初始化 XText 类的新实例。Initializes a new instance of the XText class.

XText(XText)

从另一个 XText 对象初始化 XText 类的新实例。Initializes a new instance of the XText class from another XText object.

属性

BaseUri

获取此 XObject 的基 URI。Gets the base URI for this XObject.

(继承自 XObject)
Document

获取此 XDocumentXObjectGets the XDocument for this XObject.

(继承自 XObject)
NextNode

获取此节点的下一个同级节点。Gets the next sibling node of this node.

(继承自 XNode)
NodeType

获取此节点的节点类型。Gets the node type for this node.

Parent

获取此 XElement 的父级 XObjectGets the parent XElement of this XObject.

(继承自 XObject)
PreviousNode

获取此节点的上一个同级节点。Gets the previous sibling node of this node.

(继承自 XNode)
Value

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

方法

AddAfterSelf(Object)

紧跟在此节点之后添加指定的内容。Adds the specified content immediately after this node.

(继承自 XNode)
AddAfterSelf(Object[])

紧跟在此节点之后添加指定的内容。Adds the specified content immediately after this node.

(继承自 XNode)
AddAnnotation(Object)

将对象添加到此 XObject 的批注列表。Adds an object to the annotation list of this XObject.

(继承自 XObject)
AddBeforeSelf(Object)

紧邻此节点之前添加指定的内容。Adds the specified content immediately before this node.

(继承自 XNode)
AddBeforeSelf(Object[])

紧邻此节点之前添加指定的内容。Adds the specified content immediately before this node.

(继承自 XNode)
Ancestors()

返回此节点的上级元素的集合。Returns a collection of the ancestor elements of this node.

(继承自 XNode)
Ancestors(XName)

返回此节点的经过筛选的上级元素的集合。Returns a filtered collection of the ancestor elements of this node. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

(继承自 XNode)
Annotation(Type)

从此 XObject 获取指定类型的第一个批注对象。Gets the first annotation object of the specified type from this XObject.

(继承自 XObject)
Annotation<T>()

从此 XObject 获取指定类型的第一个批注对象。Gets the first annotation object of the specified type from this XObject.

(继承自 XObject)
Annotations(Type)

获取此 XObject 的指定类型的批注集合。Gets a collection of annotations of the specified type for this XObject.

(继承自 XObject)
Annotations<T>()

获取此 XObject 的指定类型的批注集合。Gets a collection of annotations of the specified type for this XObject.

(继承自 XObject)
CreateReader()

创建此节点的 XmlReaderCreates an XmlReader for this node.

(继承自 XNode)
CreateReader(ReaderOptions)

使用 XmlReader 参数指定的选项创建 readerOptionsCreates an XmlReader with the options specified by the readerOptions parameter.

(继承自 XNode)
ElementsAfterSelf()

按文档顺序返回此节点后的同级元素集合。Returns a collection of the sibling elements after this node, in document order.

(继承自 XNode)
ElementsAfterSelf(XName)

按文档顺序返回此节点后经过筛选的同级元素的集合。Returns a filtered collection of the sibling elements after this node, in document order. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

(继承自 XNode)
ElementsBeforeSelf()

按文档顺序返回此节点前的同级元素集合。Returns a collection of the sibling elements before this node, in document order.

(继承自 XNode)
ElementsBeforeSelf(XName)

按文档顺序返回此节点前经过筛选的同级元素的集合。Returns a filtered collection of the sibling elements before this node, in document order. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

(继承自 XNode)
Equals(Object)

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

(继承自 Object)
GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
IsAfter(XNode)

确定当前节点是否按文档顺序显示在指定节点之后。Determines if the current node appears after a specified node in terms of document order.

(继承自 XNode)
IsBefore(XNode)

确定当前节点是否按文档顺序显示在指定节点之前。Determines if the current node appears before a specified node in terms of document order.

(继承自 XNode)
MemberwiseClone()

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

(继承自 Object)
NodesAfterSelf()

按文档顺序返回此节点后的同级节点的集合。Returns a collection of the sibling nodes after this node, in document order.

(继承自 XNode)
NodesBeforeSelf()

按文档顺序返回此节点前的同级节点的集合。Returns a collection of the sibling nodes before this node, in document order.

(继承自 XNode)
Remove()

从节点父级中删除此节点。Removes this node from its parent.

(继承自 XNode)
RemoveAnnotations(Type)

从此 XObject 移除指定类型的批注。Removes the annotations of the specified type from this XObject.

(继承自 XObject)
RemoveAnnotations<T>()

从此 XObject 移除指定类型的批注。Removes the annotations of the specified type from this XObject.

(继承自 XObject)
ReplaceWith(Object)

将此节点替换为指定的内容。Replaces this node with the specified content.

(继承自 XNode)
ReplaceWith(Object[])

将此节点替换为指定的内容。Replaces this node with the specified content.

(继承自 XNode)
ToString()

返回此节点的缩进 XML。Returns the indented XML for this node.

(继承自 XNode)
ToString(SaveOptions)

返回此节点的 XML,还可以选择禁用格式设置。Returns the XML for this node, optionally disabling formatting.

(继承自 XNode)
WriteTo(XmlWriter)

将此节点写入 XmlWriterWrites this node to an XmlWriter.

WriteToAsync(XmlWriter, CancellationToken)

将此 XText 异步写入到指定的 XmlWriterAsynchronously writes this XText to the specified XmlWriter.

事件

Changed

在此 XObject 或其任何子代发生了更改时引发。Raised when this XObject or any of its descendants have changed.

(继承自 XObject)
Changing

当此 XObject 或其任何子代要发生更改时引发。Raised when this XObject or any of its descendants are about to change.

(继承自 XObject)

显式接口实现

IXmlLineInfo.HasLineInfo()

获取一个值,该值指示此 XObject 是否具有行信息。Gets a value indicating whether or not this XObject has line information.

(继承自 XObject)
IXmlLineInfo.LineNumber

获取基础 XmlReader 为此 XObject 报告的行号。Gets the line number that the underlying XmlReader reported for this XObject.

(继承自 XObject)
IXmlLineInfo.LinePosition

获取基础 XmlReader 为此 XObject 报告的行位置。Gets the line position that the underlying XmlReader reported for this XObject.

(继承自 XObject)

扩展方法

CreateNavigator(XNode)

XPathNavigator 创建一个 XNodeCreates an XPathNavigator for an XNode.

CreateNavigator(XNode, XmlNameTable)

XPathNavigator 创建一个 XNodeCreates an XPathNavigator for an XNode. XmlNameTable 可以使 XPath 表达式的处理变得更高效。The XmlNameTable enables more efficient XPath expression processing.

XPathEvaluate(XNode, String)

计算 XPath 表达式。Evaluates an XPath expression.

XPathEvaluate(XNode, String, IXmlNamespaceResolver)

计算 XPath 表达式,使用指定的 IXmlNamespaceResolver 解析命名空间前缀。Evaluates an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

XPathSelectElement(XNode, String)

使用 XPath 表达式选择 XElementSelects an XElement using a XPath expression.

XPathSelectElement(XNode, String, IXmlNamespaceResolver)

使用 XPath 表达式选择 XElement,并使用指定的 IXmlNamespaceResolver 解析命名空间前缀。Selects an XElement using a XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

XPathSelectElements(XNode, String)

使用 XPath 表达式选择一个元素集合。Selects a collection of elements using an XPath expression.

XPathSelectElements(XNode, String, IXmlNamespaceResolver)

使用 XPath 表达式选择一个元素集合,并使用指定的 IXmlNamespaceResolver 解析命名空间前缀。Selects a collection of elements using an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

ToXPathNavigable(XNode)

返回一个访问器,该访问器可用于导航和编辑指定的 XNodeReturns an accessor that allows you to navigate and edit the specified XNode.

适用于

另请参阅