XmlNode.InnerXml Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri vagy beállítja a jelölést, amely csak a csomópont gyermekcsomópontjait jelöli.
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
Tulajdonság értéke
A csomópont gyermekcsomópontjainak jelölése, az alapértelmezett attribútumokat nem beleértve.
Kivételek
A tulajdonság beállítása olyan csomóponton, amely nem rendelkezik gyermekcsomópontokkal.
A tulajdonság beállításakor megadott XML nem megfelelő.
Példák
Az alábbi példa a tulajdonságokat és InnerText a InnerXml tulajdonságokat hasonlítja össze.
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
Megjegyzések
Ha olyan csomópontról próbálja beállítani ezt a tulajdonságot, amely nem rendelkezik gyermekcsomópontokkal( például szövegcsomópont), kivételt jelez. Ellenkező esetben a beállítás InnerXml a csomópont gyermekcsomópontjait az adott sztring elemzett tartalmára cseréli. Az elemzés az aktuális névtérkörnyezetben történik.
Ez a tulajdonság a Dokumentumobjektum-modell (DOM) Microsoft bővítménye.
Note
InnerXml nem hatékony módszer a DOM módosítására. Előfordulhat, hogy teljesítményproblémák lépnek fel az összetett csomópontok cseréjekor. Hatékonyabban hozhat létre csomópontokat, és olyan metódusokat használhat, mint InsertBeforea , InsertAfter, AppendChildés RemoveChild módosíthatja az Xml-dokumentumot.