XContainer.Descendants 메서드

정의

이 문서 또는 요소의 하위 요소가 문서순으로 들어 있는 컬렉션을 반환합니다.

오버로드

Descendants()

이 문서 또는 요소의 하위 요소가 문서순으로 들어 있는 컬렉션을 반환합니다.

Descendants(XName)

이 문서 또는 요소의 하위 요소가 문서순으로 들어 있는 필터링된 컬렉션을 반환합니다. 일치하는 XName이 있는 요소만 컬렉션에 포함됩니다.

설명

이 메서드는 지연된 실행을 사용합니다.

Descendants()

이 문서 또는 요소의 하위 요소가 문서순으로 들어 있는 컬렉션을 반환합니다.

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Descendants();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants ();
member this.Descendants : unit -> seq<System.Xml.Linq.XElement>
Public Function Descendants () As IEnumerable(Of XElement)

반환

IEnumerable<XElement>

IEnumerable<T>의 하위 요소가 들어 있는 XElementXContainer입니다.

예제

다음 예제에서는 XML 트리를 만든 다음 이 축 메서드를 사용하여 하위 항목을 검색합니다.

XElement xmlTree = new XElement("Root",  
    new XAttribute("Att1", "AttributeContent"),  
    new XElement("Child",  
        new XText("Some text"),  
        new XElement("GrandChild", "element content")  
    )  
);  
IEnumerable<XElement> de =  
    from el in xmlTree.Descendants()  
    select el;  
foreach (XElement el in de)  
    Console.WriteLine(el.Name);  
' Attributes are not nodes, so will not be returned by DescendantNodes.  
Dim xmlTree As XElement = _  
    <Root Att1="AttributeContent">  
        <Child>Some text  
            <GrandChild>element content</GrandChild>  
        </Child>  
    </Root>  
Dim de = From el In xmlTree.Descendants _  
         Select el  

For Each el In de  
    Console.WriteLine(el.Name)  
Next  

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

Child  
GrandChild  

설명

이 메서드는 결과 IEnumerable<T>에서 자신을 반환하지 않습니다. 결과에 현재 XElement 를 포함해야 하는지 확인 DescendantsAndSelf 합니다.

이 메서드는 지연된 실행을 사용합니다.

추가 정보

적용 대상

Descendants(XName)

이 문서 또는 요소의 하위 요소가 문서순으로 들어 있는 필터링된 컬렉션을 반환합니다. 일치하는 XName이 있는 요소만 컬렉션에 포함됩니다.

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Descendants(System::Xml::Linq::XName ^ name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants (System.Xml.Linq.XName name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants (System.Xml.Linq.XName? name);
member this.Descendants : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function Descendants (name As XName) As IEnumerable(Of XElement)

매개 변수

name
XName

일치시킬 XName입니다.

반환

IEnumerable<XElement>

IEnumerable<T>에서 지정된 XElement과 일치하는 하위 요소가 들어 있는 XContainerXName입니다.

예제

다음 예제에서는 요소의 모든 하위 항목을 인쇄합니다.

// Attributes are not nodes, so will not be returned by DescendantNodes.  
XElement xmlTree = new XElement("Root",  
    new XAttribute("Att1", "AttributeContent"),  
    new XElement("Child",  
        new XText("Some text"),  
        new XElement("GrandChild", "element content")  
    )  
);  
IEnumerable<XElement> de =  
    from el in xmlTree.Descendants("Child")  
    select el;  
foreach (XElement el in de)  
    Console.WriteLine(el.Name);  
' Attributes are not nodes, so will not be returned by the descendants axis.  
Dim xmlTree As XElement = _   
    <Root Att1="AttributeContent">  
         <Child>Some text  
             <GrandChild>element content</GrandChild>  
         </Child>  
     </Root>  

Dim de = From el In xmlTree...<Child> _  
         Select el  

For Each el In de  
    Console.WriteLine(el.Name)  
Next  

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

Child  

다음은 동일한 예제이지만 이 경우 XML은 네임스페이스에 있습니다. 자세한 내용은 XML 네임스페이스 작업을 참조하세요.

// Attributes are not nodes, so will not be returned by DescendantNodes.  
XNamespace aw = "http://www.adventure-works.com";  
XElement xmlTree = new XElement(aw + "Root",  
    new XAttribute(aw + "Att1", "AttributeContent"),  
    new XElement(aw + "Child",  
        new XText("Some text"),  
        new XElement(aw + "GrandChild", "element content")  
    )  
);  
IEnumerable<XElement> de =  
    from el in xmlTree.Descendants(aw + "Child")  
    select el;  
foreach (XElement el in de)  
    Console.WriteLine(el.Name);  
Imports <xmlns:aw = "http://www.adventure-works.com">  

Module Module1  
    Sub Main()  
        ' Attributes are not nodes, so will not be returned by the descendants axis.  
        Dim xmlTree As XElement = _   
            <aw:Root aw:Att1="AttributeContent">  
                 <aw:Child>Some text  
                     <aw:GrandChild>element content</aw:GrandChild>  
                 </aw:Child>  
             </aw:Root>  

        Dim de = From el In xmlTree...<aw:Child> _  
                 Select el  

        For Each el In de  
            Console.WriteLine(el.Name)  
        Next  
    End Sub  
End Module  

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

{http://www.adventure-works.com}Child  

설명

이 메서드는 지연된 실행을 사용합니다.

추가 정보

적용 대상