XmlNode.InnerXml Właściwość

Definicja

Pobiera lub ustawia znaczniki reprezentujące tylko węzły podrzędne tego węzła.

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

Wartość właściwości

String

Znaczniki węzłów podrzędnych tego węzła, które nie obejmują atrybutów domyślnych.

Wyjątki

Ustawienie tej właściwości w węźle, który nie może mieć węzłów podrzędnych.

Kod XML określony podczas ustawiania tej właściwości nie jest poprawnie sformułowany.

Przykłady

Poniższy przykład porównuje InnerText właściwości i 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

Uwagi

Próba ustawienia tej właściwości z węzła, który nie może mieć węzłów podrzędnych, na przykład węzła tekstowego, zgłasza wyjątek. W przeciwnym razie ustawienie InnerXml zastępuje podrzędne węzły węzła zawartością przeanalizowanego ciągu. Analizowanie odbywa się w bieżącym kontekście przestrzeni nazw.

Ta właściwość jest rozszerzeniem firmy Microsoft do modelu obiektów dokumentów (DOM).

Uwaga

InnerXml nie jest efektywnym sposobem modyfikowania modelu DOM. Podczas zastępowania złożonych węzłów mogą wystąpić problemy z wydajnością. Wydajniejsze jest konstruowanie węzłów i używanie metod, takich jak InsertBefore, InsertAfter, AppendChildi w RemoveChild celu zmodyfikowania dokumentu XML.

Dotyczy