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 from a TextReader.
Note: This sample follows on from the How do I...Read XML from a file? topic.
VB ReadXmlStream.exe
[This sample can be found at D:\inetpub\wwwroot\quickstart.developerfusion.co.uk\QuickStart\howto\samples\Xml\ReadXmlStream\]
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 hence requires no program changes if, for instance, the source of a stream changes.
This sample creates a StringReader class that builds up an XML string. Since 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);
C#
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.
|