Sdílet prostřednictvím


XmlDocument.CreateDocumentType(String, String, String, String) Metoda

Definice

Vrátí nový XmlDocumentType objekt.

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

Parametry

name
String

Název typu dokumentu

publicId
String

Veřejný identifikátor typu dokumentu nebo null. Můžete zadat veřejný identifikátor URI a také systémový identifikátor k identifikaci umístění externí podmnožina DTD.

systemId
String

Systémový identifikátor typu dokumentu nebo null. Určuje adresu URL umístění souboru pro externí podmnožinu DTD.

internalSubset
String

Interní podmnožina typu dokumentu dTD nebo null.

Návraty

XmlDocumentTypeNový .

Příklady

Následující příklad vytvoří uzel DocumentType a přidá ho do dokumentu 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

Poznámky

Vrácený uzel bude obsahovat parsované Entities a Notations kolekce.

I když tato metoda vytvoří nový objekt v kontextu dokumentu, nepřidá automaticky nový objekt do stromu dokumentu. Chcete-li přidat nový objekt, musíte explicitně volat jednu z metod vložení uzlu.

Podle doporučení W3C Extensible Markup Language (XML) 1.0 jsou uzly DocumentType povoleny pouze v uzlech Document. Každý z nich XmlDocument může mít pouze jeden uzel DocumentType. Uzel DocumentType musí být také vložen před kořenový prvek objektu XmlDocument (pokud dokument již obsahuje kořenový prvek, nelze přidat uzel DocumentType). Pokud se předané parametry nekombinují, aby se vytvořil platný XmlDocumentType, je vyvolán výjimka.

Poznámky pro dědice

Tato metoda má požadavek na dědičnost. K přepsání CreateDocumentType metody je vyžadována úplná důvěryhodnost.

Tato metoda je rozšířením Microsoftu pro model DOM (Document Object Model).

Platí pro