XmlDocument.CreateCDataSection(String) Método

Definição

Cria um XmlCDataSection contendo os dados especificados.

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

Parâmetros

data
String

O conteúdo do novo XmlCDataSection.

Devoluções

O novo XmlCDataSection.

Exemplos

O exemplo seguinte cria um nó CDATA e adiciona-o ao documento.

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

Observações

Embora este método crie o novo objeto no contexto do documento, não adiciona automaticamente o novo objeto à árvore do documento. Para adicionar o novo objeto, deve chamar explicitamente um dos métodos de inserção de nó.

De acordo com a recomendação W3C Extensible Markup Language (XML) 1.0, os nós CDataSection são permitidos dentro dos nós Element e nos nós EntityReference quando o nó EntityReference não é filho de um nó Attribute.

Aplica-se a