XDeclaration 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 XDeclaration 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| XDeclaration(XDeclaration) |
從另一個XDeclaration物件初始化該XDeclaration類別的新實例。 |
| XDeclaration(String, String, String) |
初始化一個以指定版本、編碼及獨立狀態的新類別實例 XDeclaration 。 |
XDeclaration(XDeclaration)
從另一個XDeclaration物件初始化該XDeclaration類別的新實例。
public:
XDeclaration(System::Xml::Linq::XDeclaration ^ other);
public XDeclaration(System.Xml.Linq.XDeclaration other);
new System.Xml.Linq.XDeclaration : System.Xml.Linq.XDeclaration -> System.Xml.Linq.XDeclaration
Public Sub New (other As XDeclaration)
參數
- other
- XDeclaration
用來 XDeclaration 初始化這個 XDeclaration 物件。
備註
此建構器主要用於內部製作 XML 樹的深度複製。
另請參閱
適用於
XDeclaration(String, String, String)
初始化一個以指定版本、編碼及獨立狀態的新類別實例 XDeclaration 。
public:
XDeclaration(System::String ^ version, System::String ^ encoding, System::String ^ standalone);
public XDeclaration(string version, string encoding, string standalone);
public XDeclaration(string? version, string? encoding, string? standalone);
new System.Xml.Linq.XDeclaration : string * string * string -> System.Xml.Linq.XDeclaration
Public Sub New (version As String, encoding As String, standalone As String)
參數
- version
- String
XML 的版本,通常是「1.0」。
- encoding
- String
XML 文件的編碼。
- standalone
- String
包含「是」或「否」的字串,用以指定 XML 是獨立的還是需要外部實體解析。
範例
以下範例建立一份包含宣告的文件。
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("This is a comment"),
new XElement("Root", "content")
);
doc.Save("Root.xml");
Console.WriteLine(File.ReadAllText("Root.xml"));
Dim doc As XDocument = _
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--This is a comment-->
<Root>content</Root>
doc.Save("Root.xml")
Console.WriteLine(File.ReadAllText("Root.xml"))
此範例會產生下列輸出:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--This is a comment-->
<Root>content</Root>