I have xml that looks like this:
<Doc>
<Thing>
<ID type="One">Fred</ID>
</Thing>
<Thing>
<ID>Bill</ID>
</Thing>
<Thing>
<ID type="Two">John</ID>
</Thing>
</Doc>
I can write LINQ to find the type=”One” nodes. (or type=”Two”)
Dim ThingList As IEnumerable(Of XElement) = _
From el In doc...<Thing>.<ID> _
Where el.Attribute("type").Value = "One" _
Select el
How would I write a linq query to find the ID node that doesn’t have a type attribute at all?
You should use the fact that
Attribute()will return null/nothing if there’s no such attribute.In C# I would use:
My guess is that the VB you want is: