XmlDocument.CreateDocumentType(String, String, String, String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个新 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。 指定外部 DTD 子集的文件位置的 URL。
- 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
注解
返回的节点将经过分析和EntitiesNotations集合。
尽管此方法在文档上下文中创建新对象,但它不会自动将新对象添加到文档树。 若要添加新对象,必须显式调用其中一个节点插入方法。
根据 W3C 可扩展标记语言 (XML) 1.0 建议,DocumentType 节点只能在文档节点内使用。 每个 XmlDocument 节点只能有一个 DocumentType 节点。 DocumentType 节点还必须插入到 的 XmlDocument 根元素之前(如果文档已有根元素,则不能添加 DocumentType 节点)。
如果传递的参数未组合以生成有效 XmlDocumentType,则会引发异常。
继承者说明
此方法具有继承需求。 重写 CreateDocumentType 方法需要完全信任。
此方法是文档对象模型(DOM)的Microsoft扩展。