XElement.AncestorsAndSelf Method returns a collection of elements that contain this element, and the ancestors of this element. : XElement « XML LINQ « VB.Net
XElement.AncestorsAndSelf Method returns a collection of elements that contain this element, and the ancestors of this element.
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Collections
Imports System.Collections.Generic
Public Class MainClass1s
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) = _
From el In GC.AncestorsAndSelf() _
Select el
For Each el In aas
Console.WriteLine(el.Name)
Next
End Sub
End Class