XmlNode.InnerText Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the concatenated values of the node and all its child nodes.

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

public virtual string InnerText { get; set; }

Property Value

Type: System.String

The concatenated values of the node and all its child nodes.

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();
                "<elem>some text<child/>more text</elem>" +

    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...");

    // 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 );


Display the InnerText of the element...
some textmore text
Display the InnerXml of the element...
some text<child />more text
<elem>Text containing &lt;markup/&gt; will have char(&lt;) and char(&gt;) escape
<elem>Text containing <markup />.</elem>

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top