XNode.Ancestors Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns a collection of the ancestor elements of this node.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Return Value
Type: System.Collections.Generic.IEnumerable(Of XElement)An IEnumerable(Of T) of XElement of the ancestor elements of this node.
The following example uses this method to enumerate the ancestors of a node.
Dim output As New StringBuilder Dim xmlTree As XElement = _ <Root> <Child> <GrandChild>content</GrandChild> </Child> </Root> Dim grandChild As IEnumerable(Of XElement) = xmlTree...<GrandChild> For Each el In grandChild.Ancestors() output.Append(el.Name) output.Append(Environment.NewLine) Next OutputTextBlock.Text = output.ToString()
Show: