XDocument.Root 속성

정의

이 문서에 대한 XML 트리의 루트 요소를 가져옵니다.

public:
 property System::Xml::Linq::XElement ^ Root { System::Xml::Linq::XElement ^ get(); };
public System.Xml.Linq.XElement Root { get; }
public System.Xml.Linq.XElement? Root { get; }
member this.Root : System.Xml.Linq.XElement
Public ReadOnly Property Root As XElement

속성 값

XML 트리의 루트 XElement 입니다.

예제

다음은 이 속성을 사용하여 문서의 루트 요소를 가져오는 예제입니다.

XDocument doc = new XDocument(
    new XComment("This is a comment."),
    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.")
);
Console.WriteLine(doc.Root.Name.ToString());
Dim doc As XDocument = _
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <!--This is a comment.-->
    <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>
        <!--This is another comment.-->
    </Pubs>

Console.WriteLine(doc.Root.Name.ToString())

이 예제는 다음과 같은 출력을 생성합니다.

Pubs

설명

이 속성은 루트 XElement트리에 대해 작성할 때와 동일한 컨텍스트에서 LINQ to XML 쿼리를 작성하려는 경우에 유용합니다. 자세한 내용은 XDocument 쿼리와 XElement 쿼리 를 참조하세요.

적용 대상

추가 정보