XmlElement.InnerText 속성

정의

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

public:
 virtual property System::String ^ InnerText { System::String ^ get(); void set(System::String ^ value); };
public override string InnerText { get; set; }
member this.InnerText : string with get, set
Public Overrides Property InnerText As String

속성 값

String

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

예제

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

#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 );
}
// This example produces the following results:
//
// Display the InnerText of the element...
// some textmore text
// Display the InnerXml of the element...
// some text<child />more text
// <elem>Text containing <markup/> will have char(<) and char(>) escaped.</elem>
// <elem>Text containing <markup />.</elem>
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 );
  }
}
// This example produces the following results:
//
// Display the InnerText of the element...
// some textmore text
// Display the InnerXml of the element...
// some text<child />more text
// <elem>Text containing <markup/> will have char(<) and char(>) escaped.</elem>
// <elem>Text containing <markup />.</elem>
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
' This example produces the following results:
'
' Display the InnerText of the element...
' some textmore text
' Display the InnerXml of the element...
' some text<child />more text
' <elem>Text containing <markup/> will have char(<) and char(>) escaped.</elem>
' <elem>Text containing <markup />.</elem>

설명

이 속성을 설정하면 자식 노드가 유지되지 않도록 모든 자식이 지정된 문자열의 구문 분석된 내용으로 바뀝니다. 설정 작업 후 유일한 자식 노드는 텍스트 노드입니다.

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

적용 대상