XmlText Class

Represents a text node.

Namespace: System.Xml

Assembly: System.Xml (in System.Xml.dll)

Inheritance: System.Object > System.Xml.XmlNode > System.Xml.XmlCharacterData > System.Xml.XmlText

Derived classes: XmlCDataSection, XmlWhitespace

Remarks

XmlText inherits from XmlCharacterData, which provides methods for accessing and manipulating the value of the text node. When parsing an XML document, text nodes that are not significant whitespace are parsed as XmlText nodes.

Significant whitespace is parsed as XmlWhitespace nodes. CData sections are parsed as XmlCDataSection nodes, which is a derived class of XmlText.

The Value property inherited from XmlCharacterData gets or sets the text content of the node.

Constructors

XmlText(string prefix, string localName, string namespaceURI, System.Xml.XmlDocument doc)

Initializes a new instance of the XmlText class.

XmlText(string value, System.Xml.XmlDocument doc)

Initializes a new instance of the XmlText class with the specified text value and document.

Properties

string Data Inherited from System.Xml.XmlCharacterData

Gets or sets the text content of this node.

string InnerText Inherited from System.Xml.XmlNode

Gets or sets a value indicating whether to load all of the markup contained in the node, and parse it as HTML.

string InnerXml Inherited from System.Xml.XmlNode

Gets or sets a value indicating whether to load all of the markup contained in the node, and parse it as XML.

string LocalName Inherited from System.Xml.XmlNode

Gets the local name of the current node.

string Name Inherited from System.Xml.XmlNode

Gets the qualified name of the node.

XmlNodeType NodeType Inherited from System.Xml.XmlNode

Gets the node type of the current node.

string NamespaceURI Inherited from System.Xml.XmlNode

Gets the Uniform Resource Identifier (URI) of the namespace that this node belongs to, or an empty string if it does not have one.

string Prefix Inherited from System.Xml.XmlNode

Gets the namespace prefix of the current node.

string Value Inherited from System.Xml.XmlCharacterData

Gets or sets the text content of this node.

Methods

void AppendData(string str) Inherited from System.Xml.XmlCharacterData

Appends the specified string to the end of the value of this node.

XmlNode CloneNode(bool deep) Inherited from System.Xml.XmlNode

Creates a copy of this node.

deep
Determines whether to clone all the children of the node. true to clone everything, and false to clone only the node itself.
void InsertData(int offset, string data) Inherited from System.Xml.XmlCharacterData

Inserts the specified string at the specified offset within this node.

offset
The offset at which to insert the data.
data
The string to insert.
void RemoveData(int offset, int count) Inherited from System.Xml.XmlCharacterData

Removes the specified number of characters from this node, starting at the specified offset.

offset
The offset at which to start removing characters.
count
The number of characters to remove.
void ReplaceData(int offset, int count, string data) Inherited from System.Xml.XmlCharacterData

Replaces the text node, starting at the specified offset, with the specified string.

offset
The offset at which to start replacing characters.
count
The number of characters to replace.
data
The string to replace the characters with.
string Substring(int offset, int count) Inherited from System.Xml.XmlCharacterData

Returns a portion of the text of this node.

offset
The starting offset of the substring to return.
count
The number of characters to return.

Example

using System; using System.Xml; public class Example { public static void Main(string[] args) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<root>This is some <b>text</b>.</root>"); // Get the XmlText node representing "This is some " XmlNode firstTextNode = doc.DocumentElement.FirstChild; if (firstTextNode is XmlText xmlTextNode) { Console.WriteLine($"Value: {xmlTextNode.Value}"); Console.WriteLine($"Node Type: {xmlTextNode.NodeType}"); } // Get the XmlText node representing "." XmlNode lastTextNode = doc.DocumentElement.LastChild; if (lastTextNode is XmlText lastXmlTextNode) { Console.WriteLine($"Value: {lastXmlTextNode.Value}"); } } }