XDocumentType 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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)
参数
示例
以下示例创建具有内部 DTD 的文档。 创建 XDocumentType 对象时,它指定 DTD (Pubs) 的限定名称,以及包含内部子集的字符串。 由于文档不使用公共或专用外部 DTD,因此 将 publicId
和 systemId
设置为 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.-->