Extensions.Attributes 메서드

정의

소스 컬렉션에 있는 모든 요소의 특성 컬렉션을 반환합니다.

오버로드

Attributes(IEnumerable<XElement>)

소스 컬렉션에 있는 모든 요소의 특성 컬렉션을 반환합니다.

Attributes(IEnumerable<XElement>, XName)

소스 컬렉션에 있는 모든 요소의 필터링된 특성 컬렉션을 반환합니다. 일치하는 XName이 있는 요소만 컬렉션에 포함됩니다.

설명

Visual Basic 사용자는 통합 특성 축을 사용하여 요소 컬렉션에서 특정 이름의 특성을 검색할 수 있습니다.

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

Attributes(IEnumerable<XElement>)

소스 컬렉션에 있는 모든 요소의 특성 컬렉션을 반환합니다.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<System::Xml::Linq::XAttribute ^> ^ Attributes(System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ source);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute> Attributes (this System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> source);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute> Attributes (this System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement?> source);
static member Attributes : seq<System.Xml.Linq.XElement> -> seq<System.Xml.Linq.XAttribute>
<Extension()>
Public Function Attributes (source As IEnumerable(Of XElement)) As IEnumerable(Of XAttribute)

매개 변수

source
IEnumerable<XElement>

소스 컬렉션이 들어 있는 IEnumerable<T>XElement입니다.

반환

IEnumerable<XAttribute>

소스 컬렉션에 있는 모든 요소의 특성이 들어 있는 IEnumerable<T>XAttribute입니다.

예제

다음 예제에서는 요소 컬렉션을 검색한 다음 컬렉션에 있는 모든 요소의 모든 특성 컬렉션을 검색합니다. 결과 컬렉션에는 요소의 Child1 특성이 아닌 요소의 Child2 특성 Root 만 포함됩니다.

네임스페이스 특성은 이 메서드에서 반환됩니다.

XElement xmlTree = new XElement("Root",  
    new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),  
    new XAttribute("Att1", "content1"),  
    new XAttribute("Att2", "content2"),  
    new XElement("Child1",  
        new XAttribute("Att1", "content3"),  
        new XAttribute("Att2", "content4")  
    ),  
    new XElement("Child2",  
        new XAttribute("Att1", "content5"),  
        new XAttribute("Att2", "content6")  
    )  
);  
Console.WriteLine(xmlTree);  
Console.WriteLine("-----");  

IEnumerable<XAttribute> attList =  
    from att in xmlTree.DescendantsAndSelf().Attributes()  
    select att;  

foreach (XAttribute att in attList)  
    Console.WriteLine(att);  
Dim xmlTree As XElement = _  
    <Root xmlns:aw="http://www.adventure-works.com" Att1="content1" Att2="content2">  
        <Child1 Att1="content3" Att2="content4"/>  
        <Child2 Att1="content5" Att2="content6"/>  
    </Root>  

Dim attList = _  
    From att In xmlTree.DescendantsAndSelf.Attributes _  
    Select att  

Console.WriteLine(xmlTree)  
Console.WriteLine("-----")  

For Each att As XAttribute In attList  
    Console.WriteLine(att)  
Next  

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

<Root xmlns:aw="http://www.adventure-works.com" Att1="content1" Att2="content2">  
  <Child1 Att1="content3" Att2="content4" />  
  <Child2 Att1="content5" Att2="content6" />  
</Root>  
-----  
xmlns:aw="http://www.adventure-works.com"  
Att1="content1"  
Att2="content2"  
Att1="content3"  
Att2="content4"  
Att1="content5"  
Att2="content6"  

다음은 동일한 예제이지만 이 경우 XML은 네임스페이스에 있습니다. 자세한 내용은 XML 네임스페이스 작업을 참조하세요. 네임스페이스 특성은 반환된 컬렉션에 포함되어 있습니다.

XNamespace aw = "http://www.adventure-works.com";  
XElement xmlTree = new XElement(aw + "Root",  
    new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),  
    new XAttribute(aw + "Att1", "content1"),  
    new XAttribute(aw + "Att2", "content2"),  
    new XElement(aw + "Child1",  
        new XAttribute(aw + "Att1", "content3"),  
        new XAttribute(aw + "Att2", "content4")  
    ),  
    new XElement(aw + "Child2",  
        new XAttribute(aw + "Att1", "content5"),  
        new XAttribute(aw + "Att2", "content6")  
    )  
);  
Console.WriteLine(xmlTree);  
Console.WriteLine("-----");  

IEnumerable<XAttribute> attList =  
    from att in xmlTree.DescendantsAndSelf().Attributes()  
    select att;  

foreach (XAttribute att in attList)  
    Console.WriteLine(att);  
Imports <xmlns:aw="http://www.adventure-works.com">  

Module Module1  
    Sub Main()  
        Dim xmlTree As XElement = _  
            <aw:Root xmlns:aw="http://www.adventure-works.com" aw:Att1="content1" aw:Att2="content2">  
                <aw:Child1 aw:Att1="content3" aw:Att2="content4"/>  
                <aw:Child2 aw:Att1="content5" aw:Att2="content6"/>  
            </aw:Root>  

        Dim attList = _  
            From att In xmlTree.DescendantsAndSelf.Attributes _  
            Select att  

        Console.WriteLine(xmlTree)  
        Console.WriteLine("-----")  

        For Each att As XAttribute In attList  
            Console.WriteLine(att)  
        Next  
    End Sub  
End Module  

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

<aw:Root xmlns:aw="http://www.adventure-works.com" aw:Att1="content1" aw:Att2="content2">  
  <aw:Child1 aw:Att1="content3" aw:Att2="content4" />  
  <aw:Child2 aw:Att1="content5" aw:Att2="content6" />  
</aw:Root>  
-----  
xmlns:aw="http://www.adventure-works.com"  
aw:Att1="content1"  
aw:Att2="content2"  
aw:Att1="content3"  
aw:Att2="content4"  
aw:Att1="content5"  
aw:Att2="content6"  

설명

다른 XML 프로그래밍 인터페이스와 달리 LINQ to XML 네임스페이스는 특성으로 표시됩니다.

Visual Basic 사용자는 통합 특성 축을 사용하여 요소 컬렉션에서 지정된 이름의 특성을 검색할 수 있지만 컬렉션에 있는 모든 요소의 모든 특성을 검색하는 통합 Visual Basic 축은 없습니다.

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

추가 정보

적용 대상

Attributes(IEnumerable<XElement>, XName)

소스 컬렉션에 있는 모든 요소의 필터링된 특성 컬렉션을 반환합니다. 일치하는 XName이 있는 요소만 컬렉션에 포함됩니다.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<System::Xml::Linq::XAttribute ^> ^ Attributes(System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ source, System::Xml::Linq::XName ^ name);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute> Attributes (this System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> source, System.Xml.Linq.XName name);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XAttribute> Attributes (this System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement?> source, System.Xml.Linq.XName? name);
static member Attributes : seq<System.Xml.Linq.XElement> * System.Xml.Linq.XName -> seq<System.Xml.Linq.XAttribute>
<Extension()>
Public Function Attributes (source As IEnumerable(Of XElement), name As XName) As IEnumerable(Of XAttribute)

매개 변수

source
IEnumerable<XElement>

소스 컬렉션이 들어 있는 IEnumerable<T>XElement입니다.

name
XName

일치시킬 XName입니다.

반환

IEnumerable<XAttribute>

소스 컬렉션에 있는 모든 요소의 필터링된 특성 컬렉션이 들어 있는 IEnumerable<T>XAttribute입니다. 일치하는 XName이 있는 요소만 컬렉션에 포함됩니다.

예제

다음 예제에서는 요소의 컬렉션을 검색합니다. 이 경우 요소와 Child2 요소가 포함됩니다Child1. 그런 다음, 이름이 Att1.인 자식 컬렉션의 모든 특성을 검색합니다.

XElement xmlTree = new XElement("Root",  
    new XAttribute("Att1", "content1"),  
    new XAttribute("Att2", "content2"),  
    new XElement("Child1",  
        new XAttribute("Att1", "content3"),  
        new XAttribute("Att2", "content4")  
    ),  
    new XElement("Child2",  
        new XAttribute("Att1", "content5"),  
        new XAttribute("Att2", "content6")  
    )  
);  

IEnumerable<XAttribute> attList = from att in xmlTree.Elements().Attributes("Att1")  
                                  select att;  

foreach (XAttribute att in attList)  
    Console.WriteLine(att);  
Dim xmlTree As XElement = _  
    <Root Att1="content1" Att2="content2">  
        <Child1 Att1="content3" Att2="content4">  
        </Child1>  
        <Child2 Att1="content5" Att2="content6">  
        </Child2>  
    </Root>  

Dim attList = From att In xmlTree.Elements.Attributes("Att1") _  
                          Select att  

For Each att As XAttribute In attList  
    Console.WriteLine(att)  
Next  

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

Att1="content3"  
Att1="content5"  

설명

다른 XML 프로그래밍 인터페이스와 달리 LINQ to XML 네임스페이스는 특성으로 표시됩니다.

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

추가 정보

적용 대상