Loading XML Data into an XmlTextReader

The first thing to do when parsing an XML document with an XmlTextReader is to load the stream into the reader. To do this, you simply need to create an instance of the XmlTextReader and tell it where it can find the document. The .NET Compact Framework provides several overloaded constructors for loading an XmlTextReader from different sources.

Loading an XML Stream from the Local File System

The easiest way to create an instance of the XmlTextReader is to call the constructor that takes a string representing the URI to where the XML document can be found, as shown in Listing 10.1.

Listing 10.1.
 C# XmlTextReader reader = new XmlTextReader("filename.xml"); VB Dim reader As New XmlTextReader("filename.xml") ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.