XmlNode.InnerXml 속성

정의

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

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

속성 값

String

기본 특성을 포함하지 않고 이 노드의 자식 노드에 대한 태그입니다.

예외

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

이 속성을 설정할 때 지정된 XML이 올바른 형식이 아닙니다.

예제

다음 예제에서는 속성과 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>" );
   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;
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

설명

자식 노드(예: Text 노드)를 가질 수 없는 노드에서 이 속성을 설정하려고 하면 예외가 throw됩니다. 그렇지 않으면 설정 InnerXml 은 노드의 자식 노드를 지정된 문자열의 구문 분석된 내용으로 바꿉니다. 현재 네임스페이스 컨텍스트에서 구문 분석이 수행됩니다.

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

참고

InnerXml 은 DOM을 수정하는 효율적인 방법이 아닙니다. 복잡한 노드를 교체할 때 성능 문제가 있을 수 있습니다. 노드를 생성하고 , InsertAfter``AppendChild``RemoveChild , 등의 InsertBefore메서드를 사용하고 Xml 문서를 수정하는 것이 더 효율적입니다.

적용 대상