XDocumentType 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 XDocumentType 類別的新執行個體。
多載
XDocumentType(XDocumentType) |
從其他 XDocumentType 物件初始化 XDocumentType 類別的執行個體。 |
XDocumentType(String, String, String, String) |
初始化 XDocumentType 類別的執行個體。 |
XDocumentType(XDocumentType)
從其他 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)
初始化 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.-->