XmlDocument.CreateCDataSection(String) XmlDocument.CreateCDataSection(String) XmlDocument.CreateCDataSection(String) XmlDocument.CreateCDataSection(String) Method

정의

지정된 데이터가 포함된 XmlCDataSection를 만듭니다.Creates an XmlCDataSection containing the specified data.

public:
 virtual System::Xml::XmlCDataSection ^ CreateCDataSection(System::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 String String String

XmlCDataSection의 콘텐츠입니다.The content of the new XmlCDataSection.

반환

XmlCDataSection입니다.The new XmlCDataSection.

예제

다음 예제에서는 CDATA 노드를 만들어 문서에 추가 합니다.The following example creates a CDATA node and adds it to the document.

#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
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

설명

이 메서드가 문서의 컨텍스트에서 새 개체를 만들고, 있지만 추가 되지 않습니다 자동으로 새 개체를 문서 트리에입니다.Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. 새 개체를 추가 하려면 명시적으로 노드 삽입 메서드 중 하나가 호출 해야 합니다.To add the new object, you must explicitly call one of the node insert methods.

W3C에 따라 Extensible Markup Language (XML) 1.0 권장 사항, EntityReference 노드 특성 노드의 자식이 아닙니다. 때 CDataSection 노드는 EntityReference 노드 및 요소 노드 내에 허용 됩니다.According to the W3C Extensible Markup Language (XML) 1.0 recommendation, CDataSection nodes are allowed within Element nodes and in EntityReference nodes when the EntityReference node is not a child of an Attribute node.

적용 대상