XNode.NodesBeforeSelf returns a collection of the sibling nodes before this node
Imports System
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 = New XElement("Root", _
New XText("Text content."), _
New XElement("Child1", "child1 content"), _
New XElement("Child2", "child2 content"), _
New XText("More text content."), _
New XElement("child3", "child3 content") _
)
Dim child As XElement = xmlTree.Element("Child2")
Dim nodes As IEnumerable(Of XNode) = _
From node In child.NodesBeforeSelf() _
Select node
For Each node As XNode In nodes
Dim s As String = ""
If node.NodeType = XmlNodeType.Text Then
s = DirectCast(node, XText).Value
End If
Console.WriteLine("Node type: {0} {1}", node.NodeType, s)
Next
End Sub
End Class
Related examples in the same category