BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in .NET XML, System.XML

 
 
Page 18467 of 19311

Introducing the XMLTextReader

Blogger : XML Tips and Tricks
All posts : All posts by XML Tips and Tricks
Category : .NET XML, System.XML
Blogged date : 2004 Nov 29

The .NET Framework provides a variety of classes and methods to manipulate XML. However, many times an application requires read only access to an XML Data file. This is the perfect situation for the XMLReader. This abstract class provides a fast forward only cursor for XML files and is used in both the XMLNodeReader and XMlTextReader .NET classes. The XMLTextReader reads records sequentially and allows the skipping of element that may not be needed. Overall, this improves the performance as your traverse the DOM tree.

 

The XMLTextReader provides a cursor that specifies the node in the document. The Read method is used to advance the cursor one node at a time. When initialized the XMLTextReader cursor is positioned at the start of the document. The first call to the Read moves the cursor to the first node in the document. When there are no additional nodes to process it returns a value of false. By default the Read method doesnt stop on attribute nodes, as they are not considered part of the node structure.

 

For example, if we had an XML file that contained the following data.

 

            Major Company

 

 

The following code shows an example of using the XMLTextReader in a button on a form.

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

 

        Dim xmlFileStream As New FileStream("cust.xml", FileMode.Open)

        Dim xmlRead As New XmlTextReader(xmlFileStream)

 

        While xmlRead.Read

            xmlRead.MoveToContent()

            If xmlRead.HasValue Then

                MsgBox(xmlRead.Value)

            End If

        End While

        xmlRead.Close()

        xmlFileStream.Close()

    End Sub

 

 


Read comments or post a reply to : Introducing the XMLTextReader
Page 18467 of 19311

Newest posts
 

    Email TopXML