XDeclaration 建構函式

定義

初始化 XDeclaration 類別的新執行個體。

多載

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

包含 "yes" 或 "no" 的字串,指定是否 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>  

另請參閱

適用於