다음을 통해 공유


XmlNode.InnerXml 속성

이 노드의 자식 노드를 나타내는 태그를 가져오거나 설정합니다.

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

구문

‘선언
Public Overridable Property InnerXml As String
‘사용 방법
Dim instance As XmlNode
Dim value As String

value = instance.InnerXml

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

/** @property */
public void set_InnerXml (String value)
public function get InnerXml () : String

public function set InnerXml (value : String)

속성 값

이 노드의 자식 노드를 나타내는 태그입니다.

예외

예외 형식 조건

InvalidOperationException

자식 노드를 가질 수 없는 노드에 대해 이 속성을 설정하는 경우

XmlException

이 속성을 설정할 때 지정한 XML이 제대로 구성되지 않은 경우

설명

자식 노드를 가질 수 없는 노드(예: Text 노드)에서 이 속성을 설정하면 예외가 throw됩니다. 그렇지 않을 경우 InnerXml을 설정하면 노드의 자식 노드가 지정된 문자열의 구문 분석된 콘텐츠로 바뀝니다. 구문 분석은 현재의 네임스페이스 컨텍스트에서 이루어집니다.

이 속성은 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 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

플랫폼

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에서 지원

참고 항목

참조

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