XmlNode.InnerText Property
.NET Framework (current version)
Gets or sets the concatenated values of the node and all its child nodes.
Assembly: System.Xml (in System.Xml.dll)
Setting this property replaces all the child nodes with the parsed contents of the given string.
For leaf nodes, InnerText returns the same content as the Value property.
This property is a Microsoft extension to the Document Object Model (DOM).
The following example compares the InnerText and InnerXml properties.
using System; using System.Xml; public class Test { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<root>"+ "<elem>some text<child/>more text</elem>" + "</root>"); XmlNode elem = doc.DocumentElement.FirstChild; // Note that InnerText does not include the markup. Console.WriteLine("Display the InnerText of the element..."); Console.WriteLine( elem.InnerText ); // InnerXml includes the markup of the element. Console.WriteLine("Display the InnerXml of the element..."); Console.WriteLine(elem.InnerXml); // Set InnerText to a string that includes markup. // The markup is escaped. elem.InnerText = "Text containing <markup/> will have char(<) and char(>) escaped."; Console.WriteLine( elem.OuterXml ); // Set InnerXml to a string that includes markup. // The markup is not escaped. elem.InnerXml = "Text containing <markup/>."; Console.WriteLine( elem.OuterXml ); } }
Output:
Display the InnerText of the element... some textmore text Display the InnerXml of the element... some text<child />more text <elem>Text containing <markup/> will have char(<) and char(>) escape d.</elem> <elem>Text containing <markup />.</elem>
Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 10
.NET Framework
Available since 1.1
Show: