Sdílet prostřednictvím


XmlNode.InnerXml Vlastnost

Definice

Získá nebo nastaví značky představující pouze podřízené uzly tohoto uzlu.

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

Hodnota vlastnosti

Značky podřízených uzlů tohoto uzlu, které neobsahují výchozí atributy.

Výjimky

Nastavení této vlastnosti na uzlu, který nemůže mít podřízené uzly.

Xml zadaný při nastavení této vlastnosti není správně formátován.

Příklady

Následující příklad porovnává vlastnosti InnerText a InnerXml vlastnosti.

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

    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 );
  }
}
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 XmlNode = 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 )
    
  end sub
end class

Poznámky

Při pokusu o nastavení této vlastnosti z uzlu, který nemůže mít podřízené uzly, například textový uzel, vyvolá výjimku. Jinak nastavení InnerXml nahradí podřízené uzly uzlu parsovaným obsahem daného řetězce. Analýza se provádí v aktuálním kontextu jmenného prostoru.

Tato vlastnost je rozšířením Microsoftu pro model DOM (Document Object Model).

Poznámka:

InnerXml není efektivní způsob, jak upravit DOM. Při nahrazování složitých uzlů může dojít k problémům s výkonem. Je efektivnější vytvářet uzly a používat metody, jako InsertBeforeje , InsertAfterAppendChild, a RemoveChild upravit dokument Xml.

Platí pro