G
Guest
Article ID: 301225
I can't seem to get this code to work.
I modified it alittle so I could try and figure out the exception.
I keep getting an error on the " Do While (reader.Read()) " statement.
I'm using the books.xml file MS supplies for the sample code.
Am I that far off in left field??? or is there help available???
******************************
Option Strict On
Option Explicit On
Imports System.Xml
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Module Module1
Sub Main()
Dim reader As XmlTextReader = Nothing
Console.WriteLine("This is before the loop.")
Try
reader = New XmlTextReader("books.xml")
reader.WhitespaceHandling = WhitespaceHandling.None
reader.MoveToContent()
Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'display beginning of element.
Console.WriteLine("<" + reader.Name)
If reader.HasAttributes Then 'if attributes exist
While reader.MoveToNextAttribute()
'Display attribute name and value....
Console.Write(" {0}='{1}'", reader.Name,
reader.Value)
End While
End If
Console.WriteLine(">")
Case XmlNodeType.Text 'Display the text in each element.
Console.WriteLine(reader.Value)
Case XmlNodeType.EndElement 'Display end of element.
Console.WriteLine("</" + reader.Name)
Console.WriteLine(">")
End Select
Loop
Console.ReadLine() 'Pause
Catch e As Exception
Console.WriteLine("exception: {0}", e.ToString())
Console.WriteLine("**********************")
System.IO.StringWriter.Null.WriteLine("exception: {0}", e.ToString())
Finally
Console.WriteLine("End routine")
Console.ReadLine() 'Pause
End Try
End Sub
End Module
***************************
I can't seem to get this code to work.
I modified it alittle so I could try and figure out the exception.
I keep getting an error on the " Do While (reader.Read()) " statement.
I'm using the books.xml file MS supplies for the sample code.
Am I that far off in left field??? or is there help available???
******************************
Option Strict On
Option Explicit On
Imports System.Xml
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Module Module1
Sub Main()
Dim reader As XmlTextReader = Nothing
Console.WriteLine("This is before the loop.")
Try
reader = New XmlTextReader("books.xml")
reader.WhitespaceHandling = WhitespaceHandling.None
reader.MoveToContent()
Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'display beginning of element.
Console.WriteLine("<" + reader.Name)
If reader.HasAttributes Then 'if attributes exist
While reader.MoveToNextAttribute()
'Display attribute name and value....
Console.Write(" {0}='{1}'", reader.Name,
reader.Value)
End While
End If
Console.WriteLine(">")
Case XmlNodeType.Text 'Display the text in each element.
Console.WriteLine(reader.Value)
Case XmlNodeType.EndElement 'Display end of element.
Console.WriteLine("</" + reader.Name)
Console.WriteLine(">")
End Select
Loop
Console.ReadLine() 'Pause
Catch e As Exception
Console.WriteLine("exception: {0}", e.ToString())
Console.WriteLine("**********************")
System.IO.StringWriter.Null.WriteLine("exception: {0}", e.ToString())
Finally
Console.WriteLine("End routine")
Console.ReadLine() 'Pause
End Try
End Sub
End Module
***************************