XmlDocument.CreateDocumentType(String, String, String, String) Methode

Definitie

Retourneert een nieuw XmlDocumentType object.

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

Parameters

name
String

Naam van het documenttype.

publicId
String

De openbare id van het documenttype of null. U kunt een openbare URI en ook een systeem-id opgeven om de locatie van de externe DTD-subset te identificeren.

systemId
String

De systeem-id van het documenttype of null. Hiermee geeft u de URL van de bestandslocatie voor de externe DTD-subset.

internalSubset
String

De interne DTD-subset van het documenttype of null.

Retouren

Het nieuwe XmlDocumentType.

Voorbeelden

In het volgende voorbeeld wordt een DocumentType-knooppunt gemaakt en toegevoegd aan een XML-document.

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

Opmerkingen

Het geretourneerde knooppunt heeft geparseerd Entities en Notations verzamelingen.

Hoewel met deze methode het nieuwe object wordt gemaakt in de context van het document, wordt het nieuwe object niet automatisch toegevoegd aan de documentstructuur. Als u het nieuwe object wilt toevoegen, moet u expliciet een van de methoden voor het invoegen van knooppunten aanroepen.

Volgens de aanbeveling W3C Extensible Markup Language (XML) 1.0 zijn DocumentType-knooppunten alleen toegestaan binnen documentknooppunten. Elk XmlDocument kan slechts één DocumentType-knooppunt hebben. Het DocumentType-knooppunt moet ook worden ingevoegd voordat het hoofdelement van het XmlDocument document (als het document al een hoofdelement heeft, kunt u geen DocumentType-knooppunt toevoegen). Als de doorgegeven parameters niet combineren om een geldige XmlDocumentTypete bouwen, wordt er een uitzondering gegenereerd.

Notities voor overnemers

Deze methode heeft een overnamevraag. Volledig vertrouwen is vereist om de CreateDocumentType methode te overschrijven.

Deze methode is een Microsoft extensie voor het Document Object Model (DOM).

Van toepassing op