Mega Code Archive

 
Categories / VB.Net / XML
 

XNode NodesAfterSelf returns a collection of the sibling nodes after this node

Imports System Imports System.Linq Imports System.Xml Imports System.Xml.Schema 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.NodesAfterSelf() _             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