XmlText Class
Namespace: System.Xml
Assembly: System.Xml.dll
Overview
The XmlText
class represents the text content of an XML element or attribute. It inherits from XmlCharacterData
and provides methods to manipulate the text value.
Syntax
public class XmlText : XmlCharacterData
Constructors
Properties
Methods
Examples
Signature | Summary |
---|---|
XmlText(string data) |
Initializes a new instance of the XmlText class with the specified text. |
XmlText(string data, XmlDocument doc) |
Initializes a new instance of the XmlText class with the specified text and associates it with an XmlDocument . |
Property | Type | Summary |
---|---|---|
InnerText |
string |
Gets or sets the value of the node. |
Data |
string |
Gets or sets the text data of the node. |
NodeType |
XmlNodeType |
Always returns XmlNodeType.Text . |
Method | Signature | Summary |
---|---|---|
CloneNode |
XmlNode CloneNode(bool deep) |
Creates a duplicate of this node. |
SplitText |
XmlText SplitText(int offset) |
Splits the text node at the specified offset. |
AppendData |
void AppendData(string data) |
Appends the specified string to the end of the node's data. |
Creating and Using XmlText
// Create an XML document
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("greeting");
doc.AppendChild(root);
// Create a text node
XmlText txt = doc.CreateTextNode("Hello, world!");
root.AppendChild(txt);
// Output the XML
Console.WriteLine(doc.OuterXml);
Output:
<greeting>Hello, world!</greeting>