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

Définition

Retourne un nouvel objet XmlDocumentType.

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

Paramètres

name
String

Nom du type de document.

publicId
String

Identificateur public du type de document ou null. Vous pouvez spécifier un URI public ainsi qu'un identificateur de système pour identifier l'emplacement du sous-ensemble DTD externe.

systemId
String

Identificateur système du type de document ou null. Spécifie l'URL de l'emplacement de fichier pour le sous-ensemble DTD externe.

internalSubset
String

Sous-ensemble interne du DTD du type de document ou null.

Retours

Nouvelle XmlDocumentType.

Exemples

L’exemple suivant crée un nœud DocumentType et l’ajoute à un document XML.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   
   //Create a document type node and  
   //add it to the document.
   XmlDocumentType^ doctype;
   doctype = doc->CreateDocumentType( "book", nullptr, nullptr, "<!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 );
}

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

Remarques

Le nœud retourné aura des collections analysées Entities et Notations .

Bien que cette méthode crée le nouvel objet dans le contexte du document, elle n’ajoute pas automatiquement le nouvel objet à l’arborescence du document. Pour ajouter le nouvel objet, vous devez appeler explicitement l’une des méthodes d’insertion de nœud.

Selon la recommandation XML (Extensible Markup Language) 1.0 du W3C, les nœuds DocumentType sont uniquement autorisés dans les nœuds Document. Chacun XmlDocument ne peut avoir qu’un seul nœud DocumentType. Le nœud DocumentType doit également être inséré avant l’élément racine du XmlDocument (si le document a déjà un élément racine, vous ne pouvez pas ajouter de nœud DocumentType). Si les paramètres passés ne se combinent pas pour générer un valide XmlDocumentType, une exception est levée.

Notes pour les héritiers

Cette méthode a une demande d’héritage. Une confiance totale est requise pour remplacer la CreateDocumentType méthode .

Cette méthode est une extension Microsoft du DOM (Document Object Model).

S’applique à