Mega Code Archive

 
Categories / VB.Net / XML
 

Loop through the xml nodes

Imports System Imports System.Xml Imports System.Xml.XPath Public Class MainClass     Public Shared Sub Main()         Dim xmlTree As XDocument = _              <?xml version="1.0" encoding="utf-8"?>             <!--a comment-->             <?xml-stylesheet type='text/xsl' href='hello.xsl'?>             <Root Att="attContent">                 <Child1>content</Child1>                 <Child2>Text content</Child2>             </Root>         For Each node In xmlTree.Nodes             Console.WriteLine(node.NodeType.ToString())             If node.NodeType = XmlNodeType.Element Then                 For Each att In DirectCast(node, XElement).Attributes                     Console.WriteLine(att.NodeType.ToString())                 Next                 For Each node2 In DirectCast (node, XElement).Nodes()                     Console.WriteLine(node2.NodeType.ToString())                     If node2.NodeType = XmlNodeType.Element Then                         For Each node3 In DirectCast (node2, XElement).Nodes                             Console.WriteLine(node3.NodeType.ToString())                         Next                     End If                 Next             End If         Next     End Sub End Class