Share via


XmlDocument.CreateDocumentType(String, String, String, String) Yöntem

Tanım

Yeni XmlDocumentType bir nesne döndürür.

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

Parametreler

name
String

Belge türünün adı.

publicId
String

Veya belge türünün nullortak tanımlayıcısı. Dış DTD alt kümesinin konumunu belirlemek için bir genel URI ve sistem tanımlayıcısı belirtebilirsiniz.

systemId
String

Veya belge türünün nullsistem tanımlayıcısı. Dış DTD alt kümesi için dosya konumunun URL'sini belirtir.

internalSubset
String

Veya nullbelge türünün DTD iç alt kümesi.

Döndürülenler

Yeni XmlDocumentType.

Örnekler

Aşağıdaki örnek bir DocumentType düğümü oluşturur ve bunu bir XML belgesine ekler.

#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

Açıklamalar

Döndürülen düğüm ayrıştırılmış Entities ve Notations koleksiyonlara sahip olacaktır.

Bu yöntem yeni nesneyi belge bağlamında oluştursa da, yeni nesneyi belge ağacına otomatik olarak eklemez. Yeni nesneyi eklemek için düğüm ekleme yöntemlerinden birini açıkça çağırmanız gerekir.

W3C Genişletilebilir Biçimlendirme Dili (XML) 1.0 önerisine göre, DocumentType düğümlerine yalnızca Belge düğümleri içinde izin verilir. Her XmlDocument biri yalnızca bir DocumentType düğümüne sahip olabilir. DocumentType düğümü de öğesinin kök öğesinden XmlDocument önce eklenmelidir (belgenin zaten bir kök öğesi varsa, DocumentType düğümü ekleyemezsiniz). Geçirilen parametreler geçerli XmlDocumentTypebir oluşturmak için birleştirilmiyorsa bir özel durum oluşturulur.

Devralanlara Notlar

Bu yöntemin devralma talebi vardır. Yöntemini geçersiz kılmak CreateDocumentType için tam güven gereklidir.

Bu yöntem, Belge Nesne Modeli'nin (DOM) Bir Microsoft uzantısıdır.

Şunlara uygulanır