다음을 통해 공유


XmlElement.InnerText 속성

노드와 모든 자식의 연결된 값을 가져오거나 설정합니다.

네임스페이스: System.Xml
어셈블리: System.Xml(system.xml.dll)

구문

‘선언
Public Overrides Property InnerText As String
‘사용 방법
Dim instance As XmlElement
Dim value As String

value = instance.InnerText

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

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

public override function set InnerText (value : String)

속성 값

노드와 모든 자식의 연결된 값입니다.

설명

이 속성을 설정하면 모든 자식이 구문 분석된 특정 문자열의 내용으로 바뀝니다.

이 속성은 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

예제

다음 예제에서는 InnerText 속성과 InnerXml 속성을 비교합니다.

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 XmlElement
    elem = CType (doc.DocumentElement.ChildNodes.Item(0), XmlElement)

    ' 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>");

    XmlElement elem = (XmlElement)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>" );
   XmlElement^ elem = dynamic_cast<XmlElement^>(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>");

        XmlElement elem = 
            (XmlElement)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

플랫폼

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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

XmlElement 클래스
XmlElement 멤버
System.Xml 네임스페이스