Freigeben über


XmlNode.InnerText-Eigenschaft

Ruft die verketteten Werte des Knotens und sämtlicher diesem untergeordneten Knoten ab oder legt diese fest.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

Syntax

'Declaration
Public Overridable Property InnerText As String
'Usage
Dim instance As XmlNode
Dim value As String

value = instance.InnerText

instance.InnerText = value
public virtual string InnerText { get; set; }
public:
virtual property String^ InnerText {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_InnerText ()

/** @property */
public void set_InnerText (String value)
public function get InnerText () : String

public function set InnerText (value : String)

Eigenschaftenwert

Die verketteten Werte des Knotens und aller diesem untergeordneten Knoten.

Hinweise

Durch Festlegen dieser Eigenschaft werden alle untergeordneten Knoten durch den analysierten Inhalt der angegebenen Zeichenfolge ersetzt.

Für Endknoten gibt InnerText denselben Inhalt wie die Value-Eigenschaft zurück.

Diese Eigenschaft ist eine Microsoft-Erweiterung des Dokumentobjektmodells (Document Object Model, DOM).

Beispiel

Im folgenden Beispiel werden die InnerText-Eigenschaft und die InnerXml-Eigenschaft verglichen.

Imports System
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
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 );
  }
}
#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 );
}
import System.*;
import System.Xml.*;

public class Test
{
    public static void main(String[] args)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<root>"
            + "<elem>some text<child/>more text</elem>"
            + "</root>");

        XmlNode elem = doc.get_DocumentElement().get_FirstChild();

        // Note that InnerText does not include the markup.
        Console.WriteLine("Display the InnerText of the element...");
        Console.WriteLine(elem.get_InnerText());

        // InnerXml includes the markup of the element.
        Console.WriteLine("Display the InnerXml of the element...");
        Console.WriteLine(elem.get_InnerXml());

        // Set InnerText to a string that includes markup.  
        // The markup is escaped.
        elem.set_InnerText("Text containing <markup/> will have "
            + "char(<) and char(>) escaped.");
        Console.WriteLine(elem.get_OuterXml());

        // Set InnerXml to a string that includes markup.  
        // The markup is not escaped.
        elem.set_InnerXml("Text containing <markup/>.");
        Console.WriteLine(elem.get_OuterXml());
    } //main
} //Test

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlNode-Klasse
XmlNode-Member
System.Xml-Namespace