XElement.Attributes Yöntem

Tanım

Bu öğenin öznitelik koleksiyonunu döndürür.

Aşırı Yüklemeler

Name Description
Attributes()

Bu öğenin öznitelik koleksiyonunu döndürür.

Attributes(XName)

Bu öğenin özniteliklerinden oluşan filtrelenmiş bir koleksiyon döndürür. Yalnızca eşleşen XName öznitelikler koleksiyona eklenir.

Açıklamalar

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

Attributes()

Kaynak:
XElement.cs
Kaynak:
XElement.cs
Kaynak:
XElement.cs
Kaynak:
XElement.cs
Kaynak:
XElement.cs

Bu öğenin öznitelik koleksiyonunu döndürür.

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

Döndürülenler

IEnumerable<T> Bu öğenin özniteliklerinden biriXAttribute.

Örnekler

Aşağıdaki örnek, iki özniteliği olan bir öğe oluşturur. Ardından öğesinin tüm özniteliklerini almak için bunu kullanır.

XElement xmlTree = new XElement("Root",
    new XAttribute("Att1", "content1"),
    new XAttribute("Att2", "content2")
);
IEnumerable<XAttribute> attList =
    from at in xmlTree.Attributes()
    select at;
foreach (XAttribute att in attList)
    Console.WriteLine(att);
Dim xmlTree As XElement = <Root Att1="content1" Att2="content2"/>

Dim attList As IEnumerable(Of XAttribute) = _
From at In xmlTree.Attributes() _
Select at

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

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

Att1="content1"
Att2="content2"

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.

XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = new XElement(aw + "Root",
    new XAttribute(aw + "Att1", "content1"),
    new XAttribute(aw + "Att2", "content2"),
    new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com")
);
IEnumerable<XAttribute> attList =
    from at in xmlTree.Attributes()
    select at;
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 aw:Att1="content1" aw:Att2="content2"/>

        Dim attList As IEnumerable(Of XAttribute) = _
            From at In xmlTree.Attributes() _
            Select at

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

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

aw:Att1="content1"
aw:Att2="content2"
xmlns:aw="http://www.adventure-works.com"

Açıklamalar

Döndürülen koleksiyondaki öznitelikler, öğeye eklendikleri sırayladır. XML ağacı XML'den ayrıştırıldıysa, öznitelikler belge sırasına göre döndürülür.

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

Ayrıca bkz.

Şunlara uygulanır

Attributes(XName)

Kaynak:
XElement.cs
Kaynak:
XElement.cs
Kaynak:
XElement.cs
Kaynak:
XElement.cs
Kaynak:
XElement.cs

Bu öğenin özniteliklerinden oluşan filtrelenmiş bir koleksiyon döndürür. Yalnızca eşleşen XName öznitelikler koleksiyona eklenir.

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

Parametreler

name
XName

Eşleşmesi XName için.

Döndürülenler

IEnumerable<T> XAttribute Bu öğenin özniteliklerini içeren bir öğesi. Yalnızca eşleşen XName öznitelikler koleksiyona eklenir.

Örnekler

Aşağıdaki örnekte bu kullanılır.

XElement xmlTree = new XElement("Root",
    new XAttribute("Att1", "content1"),
    new XAttribute("Att2", "content2")
);
IEnumerable<XAttribute> attList = xmlTree.Attributes("Att1");
foreach (XAttribute att in attList)
    Console.WriteLine(att);
Dim xmlTree As XElement = <Root Att1="content1" Att2="content2"/>

Dim attList As IEnumerable(Of XAttribute) = xmlTree.Attributes("Att1")

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

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

Att1="content1"

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.

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")
);
IEnumerable<XAttribute> attList = xmlTree.Attributes(aw + "Att1");
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 aw:Att1="content1" aw:Att2="content2"/>

        Dim attList As IEnumerable(Of XAttribute) = xmlTree.Attributes(GetXmlNamespace(aw) + "Att1")

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

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

aw:Att1="content1"

Açıklamalar

Öznitelik adları bir öğe içinde benzersiz olmalıdır. Bu nedenle, bu yalnızca bir öznitelik içeren bir koleksiyon döndürebilir veya boş bir koleksiyon döndürebilir.

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

Ayrıca bkz.

Şunlara uygulanır