Extensions.Attributes Yöntem

Tanım

Kaynak koleksiyondaki her öğenin özniteliklerinin koleksiyonunu döndürür.

Aşırı Yüklemeler

Name Description
Attributes(IEnumerable<XElement>)

Kaynak koleksiyondaki her öğenin özniteliklerinin koleksiyonunu döndürür.

Attributes(IEnumerable<XElement>, XName)

Kaynak koleksiyondaki her öğenin özniteliklerinin filtrelenmiş bir koleksiyonunu döndürür. Yalnızca eşleşen XName öğeler koleksiyona dahil edilir.

Açıklamalar

Visual Basic kullanıcılar, bir öğe koleksiyonundan belirli bir ada sahip öznitelikleri almak için tümleşik öznitelik eksenini kullanabilir.

Bu yöntem ertelenen yürütmeyi kullanır.

Attributes(IEnumerable<XElement>)

Kaynak:
Extensions.cs
Kaynak:
Extensions.cs
Kaynak:
Extensions.cs
Kaynak:
Extensions.cs
Kaynak:
Extensions.cs

Kaynak koleksiyondaki her öğenin özniteliklerinin koleksiyonunu döndürür.

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)

Parametreler

source
IEnumerable<XElement>

IEnumerable<T> Kaynak XElement koleksiyonu içeren bir öğe.

Döndürülenler

IEnumerable<T> Kaynak XAttribute koleksiyondaki her öğenin özniteliklerini içeren bir öğesi.

Örnekler

Aşağıdaki örnek bir öğe koleksiyonunu alır ve ardından koleksiyondaki tüm öğelerin tüm özniteliklerinden oluşan bir koleksiyon alır. Sonuçta elde edilen koleksiyonun, öğesinin özniteliklerini Child1 değil, yalnızca ve Child2 öğelerinin özniteliklerini içerdiğini Root unutmayın.

Ad alanı özniteliğinin bu yöntem tarafından döndürüldüğünü unutmayın.

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

Bu örnek aşağıdaki çıkışı oluşturur:

<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"

Aşağıda aynı örnek verilmiştir, ancak bu örnekte XML bir ad alanındadır. Daha fazla bilgi için bkz. XML Ad Alanları ile çalışma. Ad alanı özniteliğinin döndürülen koleksiyona dahil olduğuna dikkat edin.

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

Bu örnek aşağıdaki çıkışı oluşturur:

<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"

Açıklamalar

Diğer bazı XML programlama arabirimlerinden farklı olarak LINQ to XML'de ad alanlarının öznitelik olarak ortaya çıkarıldığını unutmayın.

Visual Basic kullanıcılar bir öğe koleksiyonundan belirtilen ada sahip öznitelikleri almak için tümleşik öznitelik eksenini kullansa da, bir koleksiyondaki tüm öğelerin tüm özniteliklerini almak için tümleşik Visual Basic ekseni yoktur.

Bu yöntem ertelenen yürütmeyi kullanır.

Ayrıca bkz.

Şunlara uygulanır

Attributes(IEnumerable<XElement>, XName)

Kaynak:
Extensions.cs
Kaynak:
Extensions.cs
Kaynak:
Extensions.cs
Kaynak:
Extensions.cs
Kaynak:
Extensions.cs

Kaynak koleksiyondaki her öğenin özniteliklerinin filtrelenmiş bir koleksiyonunu döndürür. Yalnızca eşleşen XName öğeler koleksiyona dahil edilir.

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)

Parametreler

source
IEnumerable<XElement>

IEnumerable<T> Kaynak XElement koleksiyonu içeren bir öğe.

name
XName

Eşleşmesi XName için.

Döndürülenler

Bunun bir IEnumerable<T> öğesi XAttribute , kaynak koleksiyondaki her öğenin özniteliklerinin filtrelenmiş bir koleksiyonunu içerir. Yalnızca eşleşen XName öğeler koleksiyona dahil edilir.

Örnekler

Aşağıdaki örnek, bu örnekte ve Child1 öğelerini içeren Child2 bir öğe koleksiyonu alır. Ardından bu alt koleksiyonun tüm özniteliklerini adıyla Att1alır.

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

Bu örnek aşağıdaki çıkışı oluşturur:

Att1="content3"
Att1="content5"

Açıklamalar

Diğer bazı XML programlama arabirimlerinden farklı olarak LINQ to XML'de ad alanlarının öznitelik olarak ortaya çıkarıldığını unutmayın.

Bu yöntem ertelenen yürütmeyi kullanır.

Ayrıca bkz.

Şunlara uygulanır