XmlDocument.CreateTextNode(String) 메서드

정의

지정된 텍스트가 있는 XmlText를 만듭니다.

public:
 virtual System::Xml::XmlText ^ CreateTextNode(System::String ^ text);
public virtual System.Xml.XmlText CreateTextNode (string text);
public virtual System.Xml.XmlText CreateTextNode (string? text);
abstract member CreateTextNode : string -> System.Xml.XmlText
override this.CreateTextNode : string -> System.Xml.XmlText
Public Overridable Function CreateTextNode (text As String) As XmlText

매개 변수

text
String

Text 노드의 텍스트입니다.

반환

XmlText

XmlText 노드입니다.

예제

다음 예제에서는 새 요소를 만들고 문서에 추가합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   
   //Create a new node and add it to the document.
   //The text node is the content of the price element.
   XmlElement^ elem = doc->CreateElement( "price" );
   XmlText^ text = doc->CreateTextNode( "19.95" );
   doc->DocumentElement->AppendChild( elem );
   doc->DocumentElement->LastChild->AppendChild( text );
   Console::WriteLine( "Display the modified XML..." );
   doc->Save( Console::Out );
}

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    //Create a new node and add it to the document.
    //The text node is the content of the price element.
    XmlElement elem = doc.CreateElement("price");
    XmlText text = doc.CreateTextNode("19.95");
    doc.DocumentElement.AppendChild(elem);
    doc.DocumentElement.LastChild.AppendChild(text);

    Console.WriteLine("Display the modified XML...");
    doc.Save(Console.Out);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>"  & _
                    "<title>Pride And Prejudice</title>"  & _
                    "</book>")
        
        'Create a new node and add it to the document.
        'The text node is the content of the price element.
        Dim elem As XmlElement = doc.CreateElement("price")
        Dim text As XmlText = doc.CreateTextNode("19.95")
        doc.DocumentElement.AppendChild(elem)
        doc.DocumentElement.LastChild.AppendChild(text)
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class

설명

이 메서드는 문서의 컨텍스트에서 새 개체를 만들지만 문서 트리에 새 개체를 자동으로 추가하지는 않습니다. 새 개체를 추가하려면 노드 삽입 메서드 중 하나를 명시적으로 호출해야 합니다.

W3C XML(Extensible Markup Language) 1.0 권장 사항에 따라 텍스트 노드는 요소, 특성 및 EntityReference 노드 내에서만 허용됩니다.

적용 대상