XmlReader.Create Method (String, XmlReaderSettings)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Creates a new instance with the specified URI and XmlReaderSettings.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- inputUri
- Type: System.String
The URI for the file containing the XML data. The XmlResolver object on the XmlReaderSettings object is used to convert the path to a canonical data representation. If XmlResolver is null, a new XmlXapResolver object is used. For more information, see the Remarks section below.
- settings
- Type: System.Xml.XmlReaderSettings
The XmlReaderSettings object used to configure the new XmlReader instance. This value can be null.
| Exception | Condition |
|---|---|
| ArgumentNullException | The inputUri value is null. |
| FileNotFoundException | The file specified by the URI cannot be found. |
| UriFormatException | 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:
Download the data. To do this, initiate an asynchronous request by using HttpWebRequest.
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.
The following example uses the Create method.
StringBuilder output = new StringBuilder(); XmlReaderSettings rs = new XmlReaderSettings(); rs.DtdProcessing = DtdProcessing.Parse; // XmlXapResolver is the default resolver. using (XmlReader reader = XmlReader.Create("nmtoken.xml", rs)) { XDocument document = XDocument.Load(reader); OutputTextBlock.Text = document.ToString(); }
The example uses nmtoken.xml file as input.
<?xml version="1.0"?> <!DOCTYPE datatype SYSTEM "nmtoken.dtd"> <datatype> <desc att="abc">abc</desc> </datatype>
The xml file references the following nmtoken.dtd file.
<!ELEMENT datatype (desc)> <!ELEMENT desc (#PCDATA)> <!ATTLIST desc att NMTOKEN #REQUIRED >