XNode.PreviousNode Property gets the previous sibling node of this node.
Imports System Imports System.Text Imports System.Xml Imports System.Xml.Schema Imports System.Linq Imports System.Collections Imports System.Collections.Generic Class MainClass Shared Sub Main() Dim xmlTree As XElement = _ <Root> <Child1>1</Child1>Some Text<Child2>2 <GrandChild>GrandChild Content</GrandChild> </Child2> <!--a comment--> <Child3>3</Child3> </Root> Dim node As XNode = xmlTree.Element("Child2") Do Dim sb As StringBuilder = New StringBuilder() sb.Append(String.Format("NodeType: {0}", node.NodeType.ToString().PadRight(10))) Select Case node.NodeType Case XmlNodeType.Text sb.Append(DirectCast(node, XText).Value) Case XmlNodeType.Element sb.Append(DirectCast(node, XElement).Name) Case XmlNodeType.Comment sb.Append(DirectCast(node, XComment).Value) End Select Console.WriteLine(sb.ToString()) node = node.PreviousNode Loop While (Not (node Is Nothing)) End Sub End Class