XElement.DescendantNodesAndSelf returns nodes that contain this element, and all descendant nodes
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Collections
Imports System.Collections.Generic
Public Class MainClass
Public Shared Sub Main()
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>Some text<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim dnas As IEnumerable(Of XNode) = _
From node In xmlTree.DescendantNodesAndSelf() _
Select node
For Each node In dnas
If TypeOf node Is XElement Then
Console.WriteLine(DirectCast(node, XElement).Name)
Else
Console.WriteLine(node)
End If
Next
End Sub
End Class