0

I'm trying to get the values of every id attribute on every node.

Getting all the attributes with .Descendants("foo").Attributes("id") is simple enough, but is there a way to get an IEnumerable (Of String) containing the values?

I'd really prefer to avoid a loop, e.g.

For Each id in myXElement.Descendants("foo").Attributes("id")
    myIEnumerable.Add(id.Value)
Next
Thalecress
  • 3,231
  • 9
  • 35
  • 47

1 Answers1

1

This is C# rather than VB, but you should be able to use the following:

  var idList = from d in myXElement.Descendants("foo")
               select d.Attribute("id").Value;

which will return a variable of type IEnumerable(Of String).

Adrian Wragg
  • 7,311
  • 3
  • 26
  • 50