XmlReader.Create Method (String)

Creates a new XmlReader instance with specified URI.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public static XmlReader Create(
	string inputUri


Type: System.String
The URI for the file containing the XML data. The XmlXapResolver class is used to convert the path to a canonical data representation. For more information, see the Remarks section below.

Return Value

Type: System.Xml.XmlReader
An XmlReader object to read the XML data.


The inputUri value is null.


The XmlReader does not have sufficient permissions to access the location of the XML data.


The file identified by the URI does not exist.


The URI format is not correct.

The inputUri parameter contains the URI to the XML file. This file must be located in the application's XAP resource, unless the XmlResolver has been changed to something other than XmlXapResolver. If you want to download the file from some other location, you must do the following:

  1. Download the data. To do this, initiate an asynchronous request by using HttpWebRequest.

  2. Create an XmlReader by calling one of the Create overloads that take Stream as a parameter, and pass the returned Stream that contains the data.

For a code example, see How to: Load an XML File from an Arbitrary URI Location with LINQ to XML.

An XmlReaderSettings object with default settings is used to create the reader. If you want 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.

    // 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...");


    // 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...");


OutputTextBlock.Text = output.ToString();

The example uses bool.xml file as input.

    <book genre='novel' ISBN='10-861003-324'>
        <title>The Handmaid's Tale</title>
    <book genre='novel' ISBN='1-861001-57-5'>
        <title>Pride And Prejudice</title>


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions