Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlReader.Create Method (XmlReader, XmlReaderSettings)

Note: This method is new in the .NET Framework version 2.0.

Creates a new XmlReader instance with the specified XmlReader and XmlReaderSettings objects.

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

public static XmlReader Create (
	XmlReader reader,
	XmlReaderSettings settings
)
public static XmlReader Create (
	XmlReader reader, 
	XmlReaderSettings settings
)
public static function Create (
	reader : XmlReader, 
	settings : XmlReaderSettings
) : XmlReader

Parameters

reader

The XmlReader object that you wish to use as the underlying reader.

settings

The XmlReaderSettings object used to configure 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

An XmlReader object that is wrapped around the specified XmlReader object.
Exception typeCondition

ArgumentNullException

The reader value is a null reference (Nothing in Visual Basic).

InvalidOperationException

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.

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

Security noteSecurity Note

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

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

-or-

Do not allow the XmlReader to open any external resources by setting the XmlResolver property to a null reference (Nothing in Visual Basic).

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.

NoteNote

To see the complete sample go to Validation Using a Wrapped XmlReader 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());


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.