Note

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

Access to this page requires authorization. You can try .

XmlElement.InnerXml 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 markup representing just the children of this node.

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

Property Value

The markup of the children of this node.

Exceptions

The XML specified when setting this property is not well-formed.

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 the children of the node with the parsed contents of the given string. The parsing is done in the current namespace context.

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

Applies to


Feedback

Was this page helpful?