Compartir a través de


XmlDocument.CreateDocumentType(String, String, String, String) Método

Definición

Devuelve un nuevo XmlDocumentType objeto.

public:
 virtual System::Xml::XmlDocumentType ^ CreateDocumentType(System::String ^ name, System::String ^ publicId, System::String ^ systemId, System::String ^ internalSubset);
public virtual System.Xml.XmlDocumentType CreateDocumentType(string name, string? publicId, string? systemId, string? internalSubset);
public virtual System.Xml.XmlDocumentType CreateDocumentType(string name, string publicId, string systemId, string internalSubset);
abstract member CreateDocumentType : string * string * string * string -> System.Xml.XmlDocumentType
override this.CreateDocumentType : string * string * string * string -> System.Xml.XmlDocumentType
Public Overridable Function CreateDocumentType (name As String, publicId As String, systemId As String, internalSubset As String) As XmlDocumentType

Parámetros

name
String

Nombre del tipo de documento.

publicId
String

Identificador público del tipo de documento o null. Puede especificar un URI público y también un identificador del sistema para identificar la ubicación del subconjunto de DTD externo.

systemId
String

Identificador del sistema del tipo de documento o null. Especifica la dirección URL de la ubicación del archivo para el subconjunto de DTD externo.

internalSubset
String

Subconjunto interno de DTD del tipo de documento o null.

Devoluciones

XmlDocumentTypeNuevo .

Ejemplos

En el ejemplo siguiente se crea un nodo DocumentType y se agrega a un documento XML.

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

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();

    //Create a document type node and
    //add it to the document.
    XmlDocumentType doctype;
    doctype = doc.CreateDocumentType("book", null, null, "<!ELEMENT book ANY>");
    doc.AppendChild(doctype);

    //Create the root element and
    //add it to the document.
    doc.AppendChild(doc.CreateElement("book"));

    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()
        
        'Create a document type node and  
        'add it to the document.
        Dim doctype As XmlDocumentType
        doctype = doc.CreateDocumentType("book", Nothing, Nothing, "<!ELEMENT book ANY>")
        doc.AppendChild(doctype)
        
        'Create the root element and 
        'add it to the document.
        doc.AppendChild(doc.CreateElement("book"))
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class

Comentarios

El nodo devuelto tendrá colecciones y Notations análisisEntities.

Aunque este método crea el nuevo objeto en el contexto del documento, no agrega automáticamente el nuevo objeto al árbol de documentos. Para agregar el nuevo objeto, debe llamar explícitamente a uno de los métodos de inserción de nodo.

Según la recomendación W3C Extensible Markup Language (XML) 1.0, los nodos DocumentType solo se permiten en los nodos Document. Cada XmlDocument uno solo puede tener un nodo DocumentType. El nodo DocumentType también debe insertarse antes del elemento raíz de XmlDocument (si el documento ya tiene un elemento raíz, no se puede agregar un nodo DocumentType). Si los parámetros pasados no se combinan para compilar un valor válido XmlDocumentType, se produce una excepción.

Notas a los desarrolladores de herederos

Este método tiene una demanda de herencia. Se requiere plena confianza para invalidar el CreateDocumentType método .

Este método es una extensión de Microsoft para document Object Model (DOM).

Se aplica a