LJM89

i tried something like

Code Block

While reader.Read()

dim val as String = reader.value()

End While

but all i get after the Xml Declaration is Empty Strings, why is this so do i use ReadElementAs... Methods and which do i use


Re: Visual Basic Language Using XmlReader (or amy other objects to read XML)

Suprotim Agarwal

Hi,

You can use the the XmlTextReader .

XmlTextReader reader = new XmlTextReader ("test.xml");

While reader.Read(){

// Do your code

End While

Eg:

Code Block

Imports System

Imports System.Xml

Namespace ReadXMLfromFile

Friend Class Class1

Shared Sub Main(ByVal args As String())

Dim reader As XmlTextReader = New XmlTextReader ("books.xml")

Do While reader.Read()

Select Case reader.NodeType

Case XmlNodeType.Element ' The node is an element.

Console.Write("<" & reader.Name)

Console.WriteLine(">")

Case XmlNodeType.Text 'Display the text in each element.

Console.WriteLine (reader.Value)

Case XmlNodeType.EndElement 'Display the end of the element.

Console.Write("</" & reader.Name)

Console.WriteLine(">")

End Select

Loop

Console.ReadLine()

End Sub

End Class

End Namespace

http://support.microsoft.com/kb/307548

HTH,
Suprotim Agarwal

-----
http://www.dotnetcurry.com
-----






Re: Visual Basic Language Using XmlReader (or amy other objects to read XML)

LJM89

does Read() means Read Line if so my code is doing the same thing is it do u know y i get empty strings "" just to understand better




Re: Visual Basic Language Using XmlReader (or amy other objects to read XML)

Suprotim Agarwal

Hi,

A Read() just reads a single character moving the stream cursor forward as it reads.

ReadLine() reads all the characters in a line till it encounters the newline.

I too am using the reader.read(). The Console.ReadLine() has got nothing to do with the program logic. It is just to view the results on the console screen at the end of execution.

HTH,
Suprotim Agarwal

-----
http://www.dotnetcurry.com
-----