XmlReader.Create Method (Stream)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Creates a new XmlReader instance using the specified stream.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- input
- Type: System.IO.Stream
The stream containing the XML data.
The XmlReader scans the first bytes of the stream looking for a byte order mark or other sign of encoding. When encoding is determined, the encoding is used to continue reading the stream, and processing continues parsing the input as a stream of (Unicode) characters.
Return Value
Type: System.Xml.XmlReaderAn XmlReader object used to read the data contained in the stream.
| Exception | Condition |
|---|---|
| NullReferenceException | The input value is null. |
| SecurityException | The XmlReader does not have sufficient permissions to access the location of the XML data. |
An XmlReaderSettings object with default settings is used to create the reader. If you wish to specify the features to support on the created reader, use the overload that takes an XmlReaderSettings object as one of its arguments, and pass in an XmlReaderSettings object with the correct settings.
The following example uses the Create method.
StringBuilder output = new StringBuilder(); // XmlXapResolver is the default resolver. using (XmlReader reader = XmlReader.Create("book.xml")) { // Moves the reader to the root element. reader.MoveToContent(); reader.ReadToFollowing("book"); // Note that ReadInnerXml only returns the markup of the node's children // so the book's attributes are not returned. output.AppendLine("Read the first book using ReadInnerXml..."); output.AppendLine(reader.ReadInnerXml()); reader.ReadToFollowing("book"); // ReadOuterXml returns the markup for the current node and its children // so the book's attributes are also returned. output.AppendLine("Read the second book using ReadOuterXml..."); output.AppendLine(reader.ReadOuterXml()); } OutputTextBlock.Text = output.ToString();
The example uses bool.xml file as input.
<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>