Mega Code Archive

 
Categories / VB.Net / XML
 

Extensions Nodes(T) Method returns a collection of the child nodes of every document and element

Imports System Imports System.Xml Imports System.Xml.XPath Public Class MainClass     Public Shared Sub Main()              Dim xmlTree As XElement = _             <Root>                 <Child>aaa<GrandChild>Text</GrandChild>bbb</Child>                 <Child>ccc<GrandChild>Text</GrandChild>ddd</Child>             </Root>                  Dim nodes = xmlTree.<Child>.Nodes()                  For Each node As XNode In nodes             Select Case node.NodeType                 Case XmlNodeType.Element                     Console.WriteLine("Element: {0}", DirectCast(node, XElement).Name)                 Case XmlNodeType.Text                     Console.WriteLine("Text: {0}", DirectCast(node, XText).Value)             End Select         Next     End Sub End Class