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 разрешены только в узлах документа. Каждый из них XmlDocument может иметь только один узел DocumentType. Узел DocumentType также необходимо вставить перед корневым элементом XmlDocument (если у документа уже есть корневой элемент, узел DocumentType добавить нельзя).
Если переданные параметры не объединяются для сборки допустимого XmlDocumentType, создается исключение.
Примечания для тех, кто наследует этот метод
Этот метод имеет требование наследования. Для переопределения CreateDocumentType метода требуется полное доверие.
Этот метод является расширением Майкрософт для модели DOM.