XmlNode::InnerText Property

 

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:
property String^ InnerText {
	virtual String^ get();
	virtual void set(String^ value);
}

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.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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 &lt;markup/&gt; will have char(&lt;) and char(&gt;) escape
d.</elem>
<elem>Text containing <markup />.</elem>

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