Reading an XML document : Read XML File « XML « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » XML » Read XML FileScreenshots 
Reading an XML document
Reading an XML document
 
Imports System.IO
Imports System.Xml

Public Class MainClass

   Shared Sub Main()

      Dim document As XmlDocument = New XmlDocument()
      document.Load("ExampleCode.xml")

      ' create XmlNodeReader for document
      Dim reader As XmlNodeReader = New XmlNodeReader(document)

      ' display each node's content
      While reader.Read

         Select Case reader.NodeType

            ' if Element, display its name
         Case XmlNodeType.Element

               ' increase tab depth
               Console.WriteLine("<" & reader.Name & ">" )

               ' if empty element, decrease depth
               If reader.IsEmptyElement Then
                   Console.WriteLine("Empty Element")
               End If

            Case XmlNodeType.Comment ' if Comment, display it
               Console.WriteLine("<!--" & reader.Value & _
                  "-->" )

            Case XmlNodeType.Text ' if Text, display it
               Console.WriteLine(reader.Value )

               ' if XML declaration, display it
            Case XmlNodeType.XmlDeclaration
               Console.WriteLine("<?" & reader.Name & " " & _
                  reader.Value & "?>" )

               ' if EndElement, display it and decrement depth
            Case XmlNodeType.EndElement
               Console.WriteLine("</" & reader.Name & ">" )


         End Select

      End While
   End Sub ' Main

End Class
 


           
         
  
Related examples in the same category
1.Output xml file to comma delimited Data
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.