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통해 지정할 수 있습니다. 문서를 인코딩하는 또 다른 방법은 쓰기 위해 LINQ to XML 전달하는 인코딩을 지정하는 XmlWriter 것입니다.

적용 대상

추가 정보