Page view counter

These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Read XML data from a stream?

This sample illustrates how to read XML from a stream using the XmlReader class. The stream could have come from a variety of sources, such as a byte stream from a server, a file, or a TextReader.

Note: This sample follows on from the How do I...Read XML from a file? topic.

VB ReadXmlStream.exe
View Source

The static Create method on the XmlReader has different overloads to specify the location of the XML data. This sample creates the XmlReader and loads the data from a stream. A stream is an abstract representation of an input or output device that is the source of or destination for data (in this case, XML data). You can write to a stream and read from a stream, which is best visualized as a flow of bytes. A stream provides independence from the device and requires no program changes if, for example, the source of a stream changes.

This sample creates a StringReader class that builds up an XML string. Because this is purely a byte stream held in memory, you can get the XmlReader to parse this stream as XML. The memory stream has no particular specified encoding.

		
'Create XmlReader and load reader from stream
reader = XmlReader.Create(stream)
VB



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.