XDocumentType 构造函数

定义

初始化 XDocumentType 类的新实例。

重载

名称 说明
XDocumentType(XDocumentType)

从另一个XDocumentType对象初始化类的XDocumentType实例。

XDocumentType(String, String, String, String)

初始化类的 XDocumentType 实例。

XDocumentType(XDocumentType)

Source:
XDocumentType.cs
Source:
XDocumentType.cs
Source:
XDocumentType.cs
Source:
XDocumentType.cs
Source:
XDocumentType.cs

从另一个XDocumentType对象初始化类的XDocumentType实例。

public:
 XDocumentType(System::Xml::Linq::XDocumentType ^ other);
public XDocumentType(System.Xml.Linq.XDocumentType other);
new System.Xml.Linq.XDocumentType : System.Xml.Linq.XDocumentType -> System.Xml.Linq.XDocumentType
Public Sub New (other As XDocumentType)

参数

other
XDocumentType

XDocumentType要从中复制的对象。

注解

在创建 XML 树的深层副本时,此构造函数主要用于内部。

另请参阅

适用于

XDocumentType(String, String, String, String)

Source:
XDocumentType.cs
Source:
XDocumentType.cs
Source:
XDocumentType.cs
Source:
XDocumentType.cs
Source:
XDocumentType.cs

初始化类的 XDocumentType 实例。

public:
 XDocumentType(System::String ^ name, System::String ^ publicId, System::String ^ systemId, System::String ^ internalSubset);
public XDocumentType(string name, string publicId, string systemId, string internalSubset);
public XDocumentType(string name, string? publicId, string? systemId, string? internalSubset);
public XDocumentType(string name, string? publicId, string? systemId, string internalSubset);
new System.Xml.Linq.XDocumentType : string * string * string * string -> System.Xml.Linq.XDocumentType
Public Sub New (name As String, publicId As String, systemId As String, internalSubset As String)

参数

name
String

一个 String 包含 DTD 的限定名称,该名称与 XML 文档的根元素的限定名称相同。

publicId
String

包含外部公共 DTD 的公共标识符的 A String

systemId
String

包含外部专用 DTD 的系统标识符的 A String

internalSubset
String

包含内部 DTD 的内部子集的 A String

示例

以下示例使用内部 DTD 创建文档。 创建 XDocumentType 对象时,它指定 DTD(Pubs)的限定名称,以及包含内部子集的字符串。 由于文档不使用公共或专用外部 DTD,因此已设置为 < a0/>

string internalSubset = @"<!ELEMENT Pubs (Book+)>
<!ELEMENT Book (Title, Author)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>";

string target = "xml-stylesheet";
string data = "href=\"mystyle.css\" title=\"Compact\" type=\"text/css\"";

XDocument doc = new XDocument(
    new XComment("This is a comment."),
    new XProcessingInstruction(target, data),
    new XDocumentType("Pubs", null, null, internalSubset),
    new XElement("Pubs",
        new XElement("Book",
            new XElement("Title", "Artifacts of Roman Civilization"),
            new XElement("Author", "Moreno, Jordao")
        ),
        new XElement("Book",
            new XElement("Title", "Midieval Tools and Implements"),
            new XElement("Author", "Gazit, Inbar")
        )
    ),
    new XComment("This is another comment.")
);
doc.Declaration = new XDeclaration("1.0", "utf-8", "true");

Console.WriteLine(doc);
Dim internalSubset = _
    "<!ELEMENT Pubs (Book+)>" & Environment.NewLine & _
    "<!ELEMENT Book (Title, Author)>" & Environment.NewLine & _
    "<!ELEMENT Title (#PCDATA)>" & Environment.NewLine & _
    "<!ELEMENT Author (#PCDATA)>"

Dim doc As XDocument = _
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <!--This is a comment.-->
    <?xml-stylesheet href="mystyle.css" title="Compact" type="text/css"?>
    <Pubs>
        <Book>
            <Title>Artifacts of Roman Civilization</Title>
            <Author>Moreno, Jordao</Author>
        </Book>
        <Book>
            <Title>Midieval Tools and Implements</Title>
            <Author>Gazit, Inbar</Author>
        </Book>
    </Pubs>
    <!--This is another comment.-->

doc.FirstNode.NextNode.AddAfterSelf(new XDocumentType("Pubs", Nothing, Nothing, internalSubset))

Console.WriteLine(doc)

此示例生成以下输出:

<!--This is a comment.-->
<?xml-stylesheet href="mystyle.css" title="Compact" type="text/css"?>
<!DOCTYPE Pubs [<!ELEMENT Pubs (Book+)>
<!ELEMENT Book (Title, Author)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>]>
<Pubs>
  <Book>
    <Title>Artifacts of Roman Civilization</Title>
    <Author>Moreno, Jordao</Author>
  </Book>
  <Book>
    <Title>Midieval Tools and Implements</Title>
    <Author>Gazit, Inbar</Author>
  </Book>
</Pubs>
<!--This is another comment.-->

另请参阅

适用于