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é identifikátor systému pro identifikaci umístění externí podmnožině 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 DTD typu dokumentu nebo null.

Návraty

Nový XmlDocumentType.

Příklady

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

Poznámky

Vrácený uzel bude mít parsované Entities a Notations kolekce.

Ačkoli tato metoda vytvoří nový objekt v kontextu dokumentu, automaticky nepřidá 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ý 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 už dokument obsahuje kořenový prvek, nemůžete přidat uzel DocumentType). Pokud se předané parametry nekombinují do sestavení platného XmlDocumentType, vyvolá se výjimka.

Poznámky pro dědice

Tato metoda má požadavek dědičnosti. K přepsání metody se vyžaduje úplný vztah důvěryhodnosti CreateDocumentType .

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

Platí pro