Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

XmlElement.InnerText Property

Definition

Namespace:
System.Xml
Assemblies:
System.Xml.dll, System.Xml.XmlDocument.dll
Assemblies:
netstandard.dll, System.Xml.ReaderWriter.dll
Assembly:
System.Xml.XmlDocument.dll
Assembly:
System.Xml.ReaderWriter.dll
Assembly:
System.Xml.dll
Assembly:
netstandard.dll
Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

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

public:
 virtual property System::String ^ InnerText { System::String ^ get(); void set(System::String ^ value); };
public override string InnerText { get; set; }
member this.InnerText : string with get, set
Public Overrides Property InnerText As String

Property Value

The concatenated values of the node and all its children.

Examples

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

 XmlElement elem = (XmlElement)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 );
 }
}
// This example produces the following results:
//
// 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;) escaped.</elem>
// <elem>Text containing <markup />.</elem>
Imports System.Xml

public class Test

 public shared sub Main()

 Dim doc as XmlDocument = new XmlDocument()
 doc.LoadXml("<root>"& _
 "<elem>some text<child/>more text</elem>" & _
 "</root>")

 Dim elem as XmlElement
 elem = CType (doc.DocumentElement.ChildNodes.Item(0), XmlElement)

 ' 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 )
 
 end sub
end class
' This example produces the following results:
'
' 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(>) escaped.</elem>
' <elem>Text containing <markup />.</elem>

Remarks

Setting this property replaces all the children with the parsed contents of the given string, so children nodes are not preserved. The only child node after the set operation is a text node.

This property is a Microsoft extension to the Document Object Model (DOM).

Applies to


Feedback

Was this page helpful?