Export (0) Print
Expand All
2 out of 6 rated this helpful - Rate this topic

XmlNode.OuterXml Property

Gets the markup representing this node and all its child nodes.

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

public virtual string OuterXml { get; }
/** @property */
public String get_OuterXml ()

public function get OuterXml () : String

Property Value

The markup containing this node and all its child nodes.
NoteNote

OuterXml does not return default attributes.

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

The following example compares output from the InnerXml and OuterXml properties.

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlNode root = doc.DocumentElement;

    // OuterXml includes the markup of current node.
    Console.WriteLine("Display the OuterXml property...");
    Console.WriteLine(root.OuterXml);
            
    // InnerXml does not include the markup of the current node.
    // As a result, the attributes are not displayed.
    Console.WriteLine();
    Console.WriteLine("Display the InnerXml property...");
    Console.WriteLine(root.InnerXml);
           
  }
}

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>"
            + "<title>Pride And Prejudice</title>"
            + "</book>");

        XmlNode root = doc.get_DocumentElement();

        // OuterXml includes the markup of current node.
        Console.WriteLine("Display the OuterXml property...");
        Console.WriteLine(root.get_OuterXml());

        // InnerXml does not include the markup of the current node.
        // As a result, the attributes are not displayed.
        Console.WriteLine();
        Console.WriteLine("Display the InnerXml property...");
        Console.WriteLine(root.get_InnerXml());
    } //main 
} //Sample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.