XmlDocument.CreateCDataSection(String) 메서드

정의

지정된 데이터가 포함된 XmlCDataSection를 만듭니다.

public:
 virtual System::Xml::XmlCDataSection ^ CreateCDataSection(System::String ^ data);
public virtual System.Xml.XmlCDataSection CreateCDataSection (string data);
public virtual System.Xml.XmlCDataSection CreateCDataSection (string? data);
abstract member CreateCDataSection : string -> System.Xml.XmlCDataSection
override this.CreateCDataSection : string -> System.Xml.XmlCDataSection
Public Overridable Function CreateCDataSection (data As String) As XmlCDataSection

매개 변수

data
String

XmlCDataSection의 콘텐츠입니다.

반환

XmlCDataSection

XmlCDataSection입니다.

예제

다음 예제에서는 CDATA 노드를 만들고 문서에 추가합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   
   //Create a CData section.
   XmlCDataSection^ CData;
   CData = doc->CreateCDataSection( "All Jane Austen novels 25% off starting 3/23!" );
   
   //Add the new node to the document.
   XmlElement^ root = doc->DocumentElement;
   root->AppendChild( CData );
   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()
  {
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    //Create a CData section.
    XmlCDataSection CData;
    CData = doc.CreateCDataSection("All Jane Austen novels 25% off starting 3/23!");

    //Add the new node to the document.
    XmlElement root = doc.DocumentElement;
    root.AppendChild(CData);

    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()
        Dim doc As New XmlDocument()
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>"  & _
                    "<title>Pride And Prejudice</title>"  & _
                    "</book>")
        
        'Create a CData section.
        Dim CData As XmlCDataSection
        CData = doc.CreateCDataSection("All Jane Austen novels 25% off starting 3/23!")
        
        'Add the new node to the document.
        Dim root As XmlElement = doc.DocumentElement
        root.AppendChild(CData)
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class

설명

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

W3C XML(Extensible Markup Language) 1.0 권장 사항에 따르면 EntityReference 노드가 특성 노드의 자식이 아닌 경우 CDataSection 노드는 요소 노드 및 EntityReference 노드 내에서 허용됩니다.

적용 대상