System.Xml.XmlDocument.InnerXml Property

Gets or sets the markup representing the children of the current node.

Syntax

public override string InnerXml { get; set; }

Value

Documentation for this section has not yet been entered.

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.

InnerXml removes redundant namespace declarations. As a result, numerous cut and paste operations do not increase the size of your document with redundant namespace declarations. Consider the following XSL document:

Example

<xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template match="stock">
         ...
     </xsl:template>
    </xsl:stylesheet>

The InnerXml property on the stylesheet node returns the following string:

Example

<xsl:template match="stock" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     ...
    </xsl:template>

Notice the additional xmlns:xsl namespace declaration which is used to preserve the node identity. If you re-insert this inner XML string, you will get back your original document. In other words, InnerXml recognizes that the xmlns:xsl namespace declaration is redundant, given that the parent xsl:stylesheet element already has the xmlns:xsl namespace delcaration, and therefore removes it.

If you move InnerXml from a document with no default namespace to a document with a default namespace, the behavior is a little different. Consider the following XML string:

Example

<test>
      <item>123</item>
    </test>

InnerXml returns a plain XML string with no namespace declarations:

Example

<item>123</item>

If you then insert this string into a document that does have a default namespace, such as the following:

Example

<test2 xmlns="urn:1">
    </test>

InnerXml parses the string in context, and the new nodes pick up the urn:1 namespace. The result looks like this:

Example

<test2 xmlns="urn:1">
      <item>123</item>
    </test>

Now when you ask for the InnerXml you get back the following:

Example

<item xmlns="urn:1">123</item>

If you explicitly want the inserted item to preserve the fact that it came from a document that had no namespace then you need to manually add an xmlns= "" declaration and insert the resulting string:

Example

<item xmlns="">123</item>

The net effect of all this is as follows:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

If InnerXml is set with text containing entity references that are not currently defined in the document, the resulting tree will contain empty EntityReference nodes.

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

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0