Editare

Partajați prin


XmlReader.Create Method

Definition

Creates a new XmlReader instance.

Overloads

Create(String, XmlReaderSettings, XmlParserContext)

Creates a new XmlReader instance by using the specified URI, settings, and context information for parsing.

Create(TextReader, XmlReaderSettings, XmlParserContext)

Creates a new XmlReader instance by using the specified text reader, settings, and context information for parsing.

Create(Stream, XmlReaderSettings, XmlParserContext)

Creates a new XmlReader instance using the specified stream, settings, and context information for parsing.

Create(Stream, XmlReaderSettings, String)

Creates a new XmlReader instance using the specified stream, base URI, and settings.

Create(XmlReader, XmlReaderSettings)

Creates a new XmlReader instance by using the specified XML reader and settings.

Create(TextReader, XmlReaderSettings, String)

Creates a new XmlReader instance by using the specified text reader, settings, and base URI.

Create(TextReader, XmlReaderSettings)

Creates a new XmlReader instance by using the specified text reader and settings.

Create(Stream, XmlReaderSettings)

Creates a new XmlReader instance with the specified stream and settings.

Create(String)

Creates a new XmlReader instance with specified URI.

Create(TextReader)

Creates a new XmlReader instance by using the specified text reader.

Create(Stream)

Creates a new XmlReader instance using the specified stream with default settings.

Create(String, XmlReaderSettings)

Creates a new XmlReader instance by using the specified URI and settings.

Remarks

For more information about this API, see Supplemental API remarks for XmlReader.Close.

Create(String, XmlReaderSettings, XmlParserContext)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance by using the specified URI, settings, and context information for parsing.

public:
 static System::Xml::XmlReader ^ Create(System::String ^ inputUri, System::Xml::XmlReaderSettings ^ settings, System::Xml::XmlParserContext ^ inputContext);
public static System.Xml.XmlReader Create (string inputUri, System.Xml.XmlReaderSettings? settings, System.Xml.XmlParserContext? inputContext);
public static System.Xml.XmlReader Create (string inputUri, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext inputContext);
static member Create : string * System.Xml.XmlReaderSettings * System.Xml.XmlParserContext -> System.Xml.XmlReader
Public Shared Function Create (inputUri As String, settings As XmlReaderSettings, inputContext As XmlParserContext) As XmlReader

Parameters

inputUri
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 XmlUrlResolver object is used.

settings
XmlReaderSettings

The settings for the new XmlReader instance. This value can be null.

inputContext
XmlParserContext

The context information required to parse the XML fragment. The context information can include the XmlNameTable to use, encoding, namespace scope, the current xml:lang and xml:space scope, base URI, and document type definition.

This value can be null.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The inputUri value is null.

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

The NameTable and NameTable properties both contain values. (Only one of these NameTable properties can be set and used).

The file specified by the URI cannot be found.

The URI format is not correct.

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

This means that the XmlReader can access any locations that does not require authentication. If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can restrict the resources that the XmlReader can access by setting the XmlResolver property to an XmlSecureResolver object.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(TextReader, XmlReaderSettings, XmlParserContext)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance by using the specified text reader, settings, and context information for parsing.

public:
 static System::Xml::XmlReader ^ Create(System::IO::TextReader ^ input, System::Xml::XmlReaderSettings ^ settings, System::Xml::XmlParserContext ^ inputContext);
public static System.Xml.XmlReader Create (System.IO.TextReader input, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext inputContext);
public static System.Xml.XmlReader Create (System.IO.TextReader input, System.Xml.XmlReaderSettings? settings, System.Xml.XmlParserContext? inputContext);
static member Create : System.IO.TextReader * System.Xml.XmlReaderSettings * System.Xml.XmlParserContext -> System.Xml.XmlReader
Public Shared Function Create (input As TextReader, settings As XmlReaderSettings, inputContext As XmlParserContext) As XmlReader

Parameters

input
TextReader

The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration isn't used by the XML reader to decode the data stream.

settings
XmlReaderSettings

The settings for the new XmlReader instance. This value can be null.

inputContext
XmlParserContext

The context information required to parse the XML fragment. The context information can include the XmlNameTable to use, encoding, namespace scope, the current xml:lang and xml:space scope, base URI, and document type definition.

This value can be null.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

The NameTable and NameTable properties both contain values. (Only one of these NameTable properties can be set and used.)

Examples

The following example creates an XmlReader object that reads an XML fragment.

string xmlFrag ="<item rk:ID='abc-23'>hammer</item> " +
                        "<item rk:ID='r2-435'>paint</item>" +
                        "<item rk:ID='abc-39'>saw</item>";

// Create the XmlNamespaceManager.
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("rk", "urn:store-items");

// Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

// Create the reader.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
XmlReader reader = XmlReader.Create(new StringReader(xmlFrag), settings, context);
Dim xmlFrag As String = "<item rk:ID='abc-23'>hammer</item> " & _
                                     "<item rk:ID='r2-435'>paint</item>" & _
                                     "<item rk:ID='abc-39'>saw</item>"

' Create the XmlNamespaceManager.
Dim nt As New NameTable()
Dim nsmgr As New XmlNamespaceManager(nt)
nsmgr.AddNamespace("rk", "urn:store-items")

' Create the XmlParserContext.
Dim context As New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None)

' Create the reader. 
Dim settings As New XmlReaderSettings()
settings.ConformanceLevel = ConformanceLevel.Fragment
Dim reader As XmlReader = XmlReader.Create(New StringReader(xmlFrag), settings, context)

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can use one of the following methods to control which resources the XmlReader can access:

-or-

  • Do not allow the XmlReader to open any external resources by setting the XmlResolver property to null.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(Stream, XmlReaderSettings, XmlParserContext)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance using the specified stream, settings, and context information for parsing.

public:
 static System::Xml::XmlReader ^ Create(System::IO::Stream ^ input, System::Xml::XmlReaderSettings ^ settings, System::Xml::XmlParserContext ^ inputContext);
public static System.Xml.XmlReader Create (System.IO.Stream input, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext inputContext);
public static System.Xml.XmlReader Create (System.IO.Stream input, System.Xml.XmlReaderSettings? settings, System.Xml.XmlParserContext? inputContext);
static member Create : System.IO.Stream * System.Xml.XmlReaderSettings * System.Xml.XmlParserContext -> System.Xml.XmlReader
Public Shared Function Create (input As Stream, settings As XmlReaderSettings, inputContext As XmlParserContext) As XmlReader

Parameters

input
Stream

The stream that contains 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.

settings
XmlReaderSettings

The settings for the new XmlReader instance. This value can be null.

inputContext
XmlParserContext

The context information required to parse the XML fragment. The context information can include the XmlNameTable to use, encoding, namespace scope, the current xml:lang and xml:space scope, base URI, and document type definition.

This value can be null.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can use one of the following methods to control which resources the XmlReader can access:

-or-

  • Do not allow the XmlReader to open any external resources by setting the XmlResolver property to null.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(Stream, XmlReaderSettings, String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance using the specified stream, base URI, and settings.

public:
 static System::Xml::XmlReader ^ Create(System::IO::Stream ^ input, System::Xml::XmlReaderSettings ^ settings, System::String ^ baseUri);
public static System.Xml.XmlReader Create (System.IO.Stream input, System.Xml.XmlReaderSettings? settings, string? baseUri);
public static System.Xml.XmlReader Create (System.IO.Stream input, System.Xml.XmlReaderSettings settings, string baseUri);
static member Create : System.IO.Stream * System.Xml.XmlReaderSettings * string -> System.Xml.XmlReader
Public Shared Function Create (input As Stream, settings As XmlReaderSettings, baseUri As String) As XmlReader

Parameters

input
Stream

The stream that contains 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.

settings
XmlReaderSettings

The settings for the new XmlReader instance. This value can be null.

baseUri
String

The base URI for the entity or document being read. This value can be null.

Security Note The base URI is used to resolve the relative URI of the XML document. Do not use a base URI from an untrusted source.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can use one of the following methods to control which resources the XmlReader can access:

-or-

  • Do not allow the XmlReader to open any external resources by setting the XmlResolver property to null.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(XmlReader, XmlReaderSettings)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance by using the specified XML reader and settings.

public:
 static System::Xml::XmlReader ^ Create(System::Xml::XmlReader ^ reader, System::Xml::XmlReaderSettings ^ settings);
public static System.Xml.XmlReader Create (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings);
public static System.Xml.XmlReader Create (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings? settings);
static member Create : System.Xml.XmlReader * System.Xml.XmlReaderSettings -> System.Xml.XmlReader
Public Shared Function Create (reader As XmlReader, settings As XmlReaderSettings) As XmlReader

Parameters

reader
XmlReader

The object that you want to use as the underlying XML reader.

settings
XmlReaderSettings

The settings for the new XmlReader instance.

The conformance level of the XmlReaderSettings object must either match the conformance level of the underlying reader, or it must be set to Auto.

Returns

An object that is wrapped around the specified XmlReader object.

Exceptions

The reader value is null.

If the XmlReaderSettings object specifies a conformance level that is not consistent with conformance level of the underlying reader.

-or-

The underlying XmlReader is in an Error or Closed state.

Examples

The following example creates a validating XmlReader object that is wrapped around an XmlNodeReader object.

// Create the XmlNodeReader object.
XmlDocument doc = new XmlDocument();
doc.Load("books.xml");
XmlNodeReader nodeReader = new XmlNodeReader(doc);

// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:bookstore-schema", "books.xsd");
settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);

// Create a validating reader that wraps the XmlNodeReader object.
XmlReader reader = XmlReader.Create(nodeReader, settings);
// Parse the XML file.
while (reader.Read());
' Create the XmlNodeReader object.
Dim doc As New XmlDocument()
doc.Load("books.xml")
Dim nodeReader As New XmlNodeReader(doc)

' Set the validation settings.
Dim settings As New XmlReaderSettings()
settings.ValidationType = ValidationType.Schema
settings.Schemas.Add("urn:bookstore-schema", "books.xsd")
AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack

' Create a validating reader that wraps the XmlNodeReader object.
Dim reader As XmlReader = XmlReader.Create(nodeReader, settings)
' Parse the XML file.
While reader.Read()
End While

Remarks

This method allows you add additional features to an underlying XmlReader object. The underlying XmlReader object can be another XmlReader object created by the Create method, or an XmlReader object created using one of the concrete XmlReader implementations.

A default XmlUrlResolver with no credentials is used to access any external resources such as a schema.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, specify an XmlResolver with the necessary credentials using the XmlReaderSettings.XmlResolver property.

Important

You can use one of the following methods to control which resources the XmlReader can access:

-or-

  • Do not allow the XmlReader to open any external resources by setting the XmlResolver property to null.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(TextReader, XmlReaderSettings, String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance by using the specified text reader, settings, and base URI.

public:
 static System::Xml::XmlReader ^ Create(System::IO::TextReader ^ input, System::Xml::XmlReaderSettings ^ settings, System::String ^ baseUri);
public static System.Xml.XmlReader Create (System.IO.TextReader input, System.Xml.XmlReaderSettings? settings, string? baseUri);
public static System.Xml.XmlReader Create (System.IO.TextReader input, System.Xml.XmlReaderSettings settings, string baseUri);
static member Create : System.IO.TextReader * System.Xml.XmlReaderSettings * string -> System.Xml.XmlReader
Public Shared Function Create (input As TextReader, settings As XmlReaderSettings, baseUri As String) As XmlReader

Parameters

input
TextReader

The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration isn't used by the XmlReader to decode the data stream.

settings
XmlReaderSettings

The settings for the new XmlReader instance. This value can be null.

baseUri
String

The base URI for the entity or document being read. This value can be null.

Security Note The base URI is used to resolve the relative URI of the XML document. Do not use a base URI from an untrusted source.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can use one of the following methods to control which resources the XmlReader can access:

-or-

  • Do not allow the XmlReader to open any external resources by setting the XmlResolver property to null.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(TextReader, XmlReaderSettings)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance by using the specified text reader and settings.

public:
 static System::Xml::XmlReader ^ Create(System::IO::TextReader ^ input, System::Xml::XmlReaderSettings ^ settings);
public static System.Xml.XmlReader Create (System.IO.TextReader input, System.Xml.XmlReaderSettings settings);
public static System.Xml.XmlReader Create (System.IO.TextReader input, System.Xml.XmlReaderSettings? settings);
static member Create : System.IO.TextReader * System.Xml.XmlReaderSettings -> System.Xml.XmlReader
Public Shared Function Create (input As TextReader, settings As XmlReaderSettings) As XmlReader

Parameters

input
TextReader

The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration isn't used by the XML reader to decode the data stream.

settings
XmlReaderSettings

The settings for the new XmlReader. This value can be null.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can use one of the following methods to control which resources the XmlReader can access:

-or-

  • Do not allow the XmlReader to open any external resources by setting the XmlResolver property to null.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(Stream, XmlReaderSettings)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance with the specified stream and settings.

public:
 static System::Xml::XmlReader ^ Create(System::IO::Stream ^ input, System::Xml::XmlReaderSettings ^ settings);
public static System.Xml.XmlReader Create (System.IO.Stream input, System.Xml.XmlReaderSettings settings);
public static System.Xml.XmlReader Create (System.IO.Stream input, System.Xml.XmlReaderSettings? settings);
static member Create : System.IO.Stream * System.Xml.XmlReaderSettings -> System.Xml.XmlReader
Public Shared Function Create (input As Stream, settings As XmlReaderSettings) As XmlReader

Parameters

input
Stream

The stream that contains 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.

settings
XmlReaderSettings

The settings for the new XmlReader instance. This value can be null.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can use one of the following methods to control which resources the XmlReader can access:

-or-

  • Do not allow the XmlReader to open any external resources by setting the XmlResolver property to null.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance with specified URI.

public:
 static System::Xml::XmlReader ^ Create(System::String ^ inputUri);
public static System.Xml.XmlReader Create (string inputUri);
static member Create : string -> System.Xml.XmlReader
Public Shared Function Create (inputUri As String) As XmlReader

Parameters

inputUri
String

The URI for the file that contains the XML data. The XmlUrlResolver class is used to convert the path to a canonical data representation.

Returns

An object that is used to read the XML data in the stream.

Exceptions

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.

Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

Examples

The following example creates an XmlReader object that reads XML data file specified by the URI.

// Create the XmlReader object.
XmlReader reader = XmlReader.Create("books.xml");
' Create the XmlReader object.
Dim reader As XmlReader = XmlReader.Create("books.xml")

Remarks

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.

A default XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, specify an XmlResolver with the necessary credentials using the XmlReaderSettings.XmlResolver property.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(TextReader)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance by using the specified text reader.

public:
 static System::Xml::XmlReader ^ Create(System::IO::TextReader ^ input);
public static System.Xml.XmlReader Create (System.IO.TextReader input);
static member Create : System.IO.TextReader -> System.Xml.XmlReader
Public Shared Function Create (input As TextReader) As XmlReader

Parameters

input
TextReader

The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration is not used by the XML reader to decode the data stream.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

Examples

The following example uses the StringReader class to read an XML string.

string xmlData ="<item productID='124390'>" +
                        "<price>5.95</price>" +
                        "</item>";

// Create the XmlReader object.
XmlReader reader = XmlReader.Create(new StringReader(xmlData));
Dim xmlData As String = "<item productID='124390'>" & _ 
                                     "<price>5.95</price>" & _ 
                                     "</item>"

' Create the XmlReader object.
Dim reader As XmlReader = XmlReader.Create(New StringReader(xmlData))

Remarks

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.

A default XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, specify an XmlResolver with the necessary credentials using the XmlReaderSettings.XmlResolver property.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(Stream)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance using the specified stream with default settings.

public:
 static System::Xml::XmlReader ^ Create(System::IO::Stream ^ input);
public static System.Xml.XmlReader Create (System.IO.Stream input);
static member Create : System.IO.Stream -> System.Xml.XmlReader
Public Shared Function Create (input As Stream) As XmlReader

Parameters

input
Stream

The stream that contains 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.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The input value is null.

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

Examples

The following example creates an XmlReader object that reads from a FileStream.


FileStream fs = new FileStream(@"C:\data\books.xml", FileMode.OpenOrCreate,
                                                                    FileAccess.Read, FileShare.Read);

// Create the XmlReader object.
XmlReader reader = XmlReader.Create(fs);
    Dim fs As New FileStream("C:\data\books.xml", FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
    
    ' Create the XmlReader object.
    Dim reader As XmlReader = XmlReader.Create(fs)

End Sub

Remarks

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.

A default XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

If the external resource is located on a network resource that requires authentication, specify an XmlResolver with the necessary credentials using the XmlReaderSettings.XmlResolver property.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to

Create(String, XmlReaderSettings)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

Creates a new XmlReader instance by using the specified URI and settings.

public:
 static System::Xml::XmlReader ^ Create(System::String ^ inputUri, System::Xml::XmlReaderSettings ^ settings);
public static System.Xml.XmlReader Create (string inputUri, System.Xml.XmlReaderSettings settings);
public static System.Xml.XmlReader Create (string inputUri, System.Xml.XmlReaderSettings? settings);
static member Create : string * System.Xml.XmlReaderSettings -> System.Xml.XmlReader
Public Shared Function Create (inputUri As String, settings As XmlReaderSettings) As XmlReader

Parameters

inputUri
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 XmlUrlResolver object is used.

settings
XmlReaderSettings

The settings for the new XmlReader instance. This value can be null.

Returns

An object that is used to read the XML data in the stream.

Exceptions

The inputUri value is null.

The file specified by the URI cannot be found.

The URI format is not correct.

Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

Examples

The following example creates an XmlReader object that supports document type definition (DTD) validation.

// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
settings.ValidationType = ValidationType.DTD;
settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);

 // Create the XmlReader object.
XmlReader reader = XmlReader.Create("itemDTD.xml", settings);

// Parse the file.
while (reader.Read()) {}
' Set the validation settings.
Dim settings As New XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse
settings.ValidationType = ValidationType.DTD
AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack

' Create the XmlReader object.
Dim reader As XmlReader = XmlReader.Create("itemDTD.xml", settings)

' Parse the file. 
While reader.Read()
End While

Remarks

By default an XmlUrlResolver with no credentials is used to access any external resources such as a document type definition (DTD), entities, schemas, and so on.

Important

Starting with the .NET Framework 4.5.2, no default XmlUrlResolver is provided. If your solution targets the .NET Framework 4.5.2 or later versions, specify an XmlResolver using the XmlReaderSettings.XmlResolver property.

This means that the XmlReader can access any locations that does not require authentication. If the external resource is located on a network resource that requires authentication, use the XmlReaderSettings.XmlResolver property to specify an XmlResolver with the necessary credentials.

Important

You can restrict the resources that the XmlReader can access by setting the XmlResolver property to an XmlSecureResolver object.

The created XmlReader object expands entity references and performs XML normalization of new line characters.

Applies to