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