Поделиться через


XmlDocument.CreateDocumentType(String, String, String, String) Метод

Определение

Возвращает новый 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

Параметры

name
String

Имя типа документа.

publicId
String

Общедоступный идентификатор типа документа или null. Можно указать общедоступный URI, а также системный идентификатор, чтобы определить расположение внешнего подмножества DTD.

systemId
String

Системный идентификатор типа документа или null. Указывает URL-адрес расположения файла для внешнего подмножества DTD.

internalSubset
String

Внутреннее подмножество DTD типа документа или null.

Возвращаемое значение

Новое XmlDocumentType.

Примеры

В следующем примере создается узел DocumentType и добавляет его в 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

Комментарии

Возвращенный узел будет анализироваться Entities и Notations коллекции.

Хотя этот метод создает новый объект в контексте документа, он не автоматически добавляет новый объект в дерево документов. Чтобы добавить новый объект, необходимо явно вызвать один из методов вставки узла.

В соответствии с рекомендацией W3C Расширяемый язык разметки (XML) 1.0 узлы DocumentType разрешены только в узлах Document. Каждый из них XmlDocument может иметь только один узел DocumentType. Узел DocumentType также должен быть вставлен перед корневым элементом XmlDocument (если документ уже имеет корневой элемент, нельзя добавить узел DocumentType). Если переданные параметры не объединяются для создания допустимого XmlDocumentType, создается исключение.

Примечания для тех, кто наследует этот метод

Этот метод имеет требование наследования. Для переопределения CreateDocumentType метода требуется полное доверие.

Этот метод является расширением Майкрософт для объектной модели документов (DOM).

Применяется к