다음을 통해 공유


XmlDocument.CreateCDataSection 메서드

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

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

구문

‘선언
Public Overridable Function CreateCDataSection ( _
    data As String _
) As XmlCDataSection
‘사용 방법
Dim instance As XmlDocument
Dim data As String
Dim returnValue As XmlCDataSection

returnValue = instance.CreateCDataSection(data)
public virtual XmlCDataSection CreateCDataSection (
    string data
)
public:
virtual XmlCDataSection^ CreateCDataSection (
    String^ data
)
public XmlCDataSection CreateCDataSection (
    String data
)
public function CreateCDataSection (
    data : String
) : XmlCDataSection

매개 변수

  • data
    XmlCDataSection의 콘텐츠입니다.

반환 값

XmlCDataSection입니다.

설명

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

W3C XML(Extensible Markup Language) 1.0 권장 사항(www.w3.org/TR/1998/REC-xml-19980210)에 따르면 CDataSection 노드는 Element 노드 안에서 사용할 수 있으며 EntityReference 노드가 Attribute 노드의 자식이 아닐 경우에는 EntityReference 노드 안에서도 사용할 수 있습니다.

예제

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

Option Explicit
Option Strict

Imports System
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 'Main
End Class 'Sample
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);
  }
}
#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 );
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        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.get_DocumentElement();
        root.AppendChild(cData);

        Console.WriteLine("Display the modified XML...");
        doc.Save(Console.get_Out());
    } //main
} //Sample

플랫폼

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

참고 항목

참조

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