Reads an XML file and displays each of the nodes. : DOM « XML « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » XML » DOM 
25.4.3.Reads an XML file and displays each of the nodes.
Option Strict
Option Explicit

Imports System
Imports System.IO
Imports System.Xml

'Reads an XML document
Public Class Sample
    Private Const filename As String = "items.xml"

    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing
        Try
             reader = New XmlTextReader(filename)
            reader.WhitespaceHandling = WhitespaceHandling.None
            While reader.Read()
                Select Case reader.NodeType
                    Case XmlNodeType.Element
                        Console.Write("<{0}>", reader.Name)
                    Case XmlNodeType.Text
                        Console.Write(reader.Value)
                    Case XmlNodeType.CDATA
                        Console.Write("CDATA:0", reader.Value)
                    Case XmlNodeType.ProcessingInstruction
                        Console.Write("<?{0} {1}?>", reader.Name, reader.Value)
                    Case XmlNodeType.Comment
                        Console.Write("<!--{0}-->", reader.Value)
                    Case XmlNodeType.XmlDeclaration
                        Console.Write("<?xml version='1.0'?>")
                    Case XmlNodeType.Document
                    Case XmlNodeType.DocumentType
                        Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value)
                    Case XmlNodeType.EntityReference
                        Console.Write(reader.Name)
                    Case XmlNodeType.EndElement
                        Console.Write("</{0}>", reader.Name)
                End Select
            End While

        Finally
            If Not (reader Is NothingThen
                reader.Close()
            End If
        End Try
    End Sub
End Class
25.4.DOM
25.4.1.DOM load
25.4.2.DOM save
25.4.3.Reads an XML file and displays each of the nodes.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.