Question

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
Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top