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.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.