XmlReader.Create Method (XmlReader, XmlReaderSettings)


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

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

Public Shared Function Create (
	reader As XmlReader,
	settings As XmlReaderSettings
) As XmlReader


Type: System.Xml.XmlReader

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

Type: System.Xml.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.

Return Value

Type: System.Xml.XmlReader

An object that is wrapped around the specified XmlReader object.

Exception Condition

The reader value is null.


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


The underlying XmlReader is in an Error or Closed state.

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.


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.

System_CAPS_security Security Note

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


  • 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.

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

' Create the XmlNodeReader object.
Dim doc As New XmlDocument()
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

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top