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
有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top