XmlNode.InnerXml Properti

Definisi

Mendapatkan atau mengatur markup yang hanya mewakili simpul anak dari simpul ini.

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

Nilai Properti

Markup simpul anak dari simpul ini, tidak termasuk atribut default.

Pengecualian

Menyetel properti ini pada simpul yang tidak dapat memiliki simpul anak.

XML yang ditentukan saat mengatur properti ini tidak terbentuk dengan baik.

Contoh

Contoh berikut membandingkan InnerText properti dan InnerXml .

#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 );
}
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

Keterangan

Mencoba mengatur properti ini dari simpul yang tidak dapat memiliki simpul anak, misalnya simpul Teks, melemparkan pengecualian. Jika tidak, pengaturan InnerXml menggantikan simpul anak simpul dengan konten yang diurai dari string yang diberikan. Penguraian dilakukan dalam konteks namespace saat ini.

Properti ini adalah ekstensi Microsoft ke Model Objek Dokumen (DOM).

Catatan

InnerXml bukan cara yang efisien untuk memodifikasi DOM. Mungkin ada masalah performa saat mengganti simpul yang kompleks. Lebih efisien untuk membuat simpul dan menggunakan metode seperti InsertBefore, , InsertAfterAppendChild, dan RemoveChild untuk memodifikasi dokumen Xml.

Berlaku untuk