How to: Retrieve a Single Attribute (LINQ to XML)
This topic explains how to retrieve a single attribute of an element, given the attribute name. This is useful for writing query expressions where you want to find an element that has a particular attribute.
The following example uses the Attribute method.
If you want to retrieve the value of the attribute, you can cast it, just as you do for with XElement objects. The following example demonstrates this.
The following example shows the same code for an attribute that is in a namespace. For more information, see Working with XML Namespaces.
Imports <xmlns:aw="http://www.adventure-works.com"> Module Module1 Sub Main() Dim cust As XElement = _ <aw:PhoneNumbers> <aw:Phone aw:type="home">555-555-5555</aw:Phone> <aw:Phone aw:type="work">555-555-6666</aw:Phone> </aw:PhoneNumbers> Dim elList As IEnumerable(Of XElement) = _ From el In cust...<aw:Phone> _ Select el For Each el As XElement In elList Console.WriteLine(el.@aw:type) Next End Sub End Module