XElement.AncestorsAndSelf (XName) returns a filtered collection of elements
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>
<Child>
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim GC As XElement = xmlTree.<Child>.<GrandChild>(0)
Dim aas As IEnumerable(Of XElement) = GC.AncestorsAndSelf("Child")
For Each el In aas
Console.WriteLine(el.Name)
Next
End Sub
End Class