XDocument.Declaration プロパティ

定義

このドキュメントの XML 宣言を取得または設定します。

public:
 property System::Xml::Linq::XDeclaration ^ Declaration { System::Xml::Linq::XDeclaration ^ get(); void set(System::Xml::Linq::XDeclaration ^ value); };
public System.Xml.Linq.XDeclaration Declaration { get; set; }
public System.Xml.Linq.XDeclaration? Declaration { get; set; }
member this.Declaration : System.Xml.Linq.XDeclaration with get, set
Public Property Declaration As XDeclaration

プロパティ値

XDeclaration

このドキュメントの XML 宣言を格納する XDeclaration

次の例では、このプロパティを使用してドキュメントの XML 宣言を取得します。

XDocument doc = new XDocument(  
    new XDeclaration("1.0", "utf-8", "yes"),  
    new XComment("This is a comment"),  
    new XElement("Root", "content")  
);  

Console.WriteLine(doc.Declaration);  
Dim doc As XDocument = _  
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>  
        <!--This is a comment-->  
        <Root>content</Root>  

Console.WriteLine(doc.Declaration)  

この例を実行すると、次の出力が生成されます。

<?xml version="1.0" encoding="utf-8" standalone="yes"?>  

注釈

場合によっては、ドキュメントの XML 宣言を作成する必要があります。 ドキュメントがスタンドアロンであることを示す場合は、このプロパティを使用する必要があります。 utf-8 以外のエンコーディングでドキュメントをエンコードする場合は、 XDeclaration. ドキュメントをエンコードするもう 1 つの方法は、書き込みのためにLINQ to XMLに渡すエンコードXmlWriterを指定することです。

適用対象

こちらもご覧ください