XDocumentType 构造函数

定义

初始化 XDocumentType 类的新实例。

重载

XDocumentType(XDocumentType)

从其他 XDocumentType 对象初始化 XDocumentType 类的实例。

XDocumentType(String, String, String, String)

初始化 XDocumentType 类的实例。

XDocumentType(XDocumentType)

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

初始化 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

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

publicId
String

一个 String,其中包含外部公共 DTD 的公共标识符。

systemId
String

一个 String,其中包含外部专用 DTD 的系统标识符。

internalSubset
String

一个 String,其中包含内部 DTD 的内部子集。

示例

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

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.-->  

另请参阅

适用于