Condividi tramite


XmlNode.InnerXml Proprietà

Definizione

Ottiene o imposta il markup che rappresenta solo i nodi figlio di questo nodo.

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

Valore della proprietà

Markup dei nodi figlio di questo nodo, senza includere gli attributi predefiniti.

Eccezioni

Impostazione di questa proprietà in un nodo che non può contenere nodi figlio.

Il codice XML specificato durante l'impostazione di questa proprietà non è ben formato.

Esempio

Nell'esempio seguente vengono confrontate le InnerText proprietà e InnerXml .

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

Commenti

Se si tenta di impostare questa proprietà da un nodo che non può avere nodi figlio, ad esempio un nodo Text, genera un'eccezione. In caso contrario, l'impostazione InnerXml sostituisce i nodi figlio del nodo con il contenuto analizzato della stringa specificata. L'analisi viene eseguita nel contesto dello spazio dei nomi corrente.

Questa proprietà è un'estensione Microsoft per il DOM (Document Object Model).

Annotazioni

InnerXml non è un modo efficiente per modificare il DOM. Potrebbero verificarsi problemi di prestazioni durante la sostituzione di nodi complessi. È più efficiente costruire nodi e usare metodi come InsertBefore, InsertAfter, AppendChilde RemoveChild per modificare il documento Xml.

Si applica a