.NET Framework Class Library
XmlReader..::.Create Method

Creates a new XmlReader instance.

Overload List

  NameDescription
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(Stream)Creates a new XmlReader instance using the specified stream.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(TextReader)Creates a new XmlReader instance with the specified TextReader.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(String)Creates a new XmlReader instance with specified URI.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(Stream, XmlReaderSettings)Creates a new XmlReader instance with the specified stream and XmlReaderSettings object.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(TextReader, XmlReaderSettings)Creates a new XmlReader instance using the specified TextReader and XmlReaderSettings objects.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(String, XmlReaderSettings)Creates a new instance with the specified URI and XmlReaderSettings.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(XmlReader, XmlReaderSettings)Creates a new XmlReader instance with the specified XmlReader and XmlReaderSettings objects.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(Stream, XmlReaderSettings, String)Creates a new XmlReader instance using the specified stream, base URI, and XmlReaderSettings object.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(Stream, XmlReaderSettings, XmlParserContext)Creates a new XmlReader instance using the specified stream, XmlReaderSettings, and XmlParserContext objects.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(TextReader, XmlReaderSettings, String)Creates a new XmlReader instance using the specified TextReader, XmlReaderSettings, and base URI.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(TextReader, XmlReaderSettings, XmlParserContext)Creates a new XmlReader instance using the specified TextReader, XmlReaderSettings, and XmlParserContext objects.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCreate(String, XmlReaderSettings, XmlParserContext)Creates a new XmlReader instance using the specified URI, XmlReaderSettings, and XmlParserContext objects.
Top
Remarks

Although Microsoft .NET Framework includes concrete implementations of the XmlReader class, such as the XmlTextReader, XmlNodeReader, and the XmlValidatingReader classes, in the 2.0 release the recommended practice is to create XmlReader instances using the Create method. For more information, see Creating XML Readers.

Security noteSecurity Note:

By default the XmlReader uses an XmlUrlResolver object with no user credentials to open resources. This means that, by default, the XmlReader can access any locations that do not require credentials. 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 nullNothingnullptra null reference (Nothing in Visual Basic).

Examples

The following example uses an XmlUrlResolver with default credentials to access a file.

Visual Basic
' Set the reader settings.
Dim settings as XmlReaderSettings = new XmlReaderSettings()
settings.IgnoreComments = true
settings.IgnoreProcessingInstructions = true
settings.IgnoreWhitespace = true
C#
// Set the reader settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
Visual C++
// Set the reader settings.
XmlReaderSettings^ settings = gcnew XmlReaderSettings;
settings->IgnoreComments = true;
settings->IgnoreProcessingInstructions = true;
settings->IgnoreWhitespace = true;

CPP_OLD
// Set the reader settings.
XmlReaderSettings* settings = new XmlReaderSettings();
settings->IgnoreComments = true;
settings->IgnoreProcessingInstructions = true;
settings->IgnoreWhitespace = true;
Visual Basic
' Create a resolver with default credentials.
Dim resolver as XmlUrlResolver = new XmlUrlResolver()
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials

' Set the reader settings object to use the resolver.
settings.XmlResolver = resolver

' Create the XmlReader object.
Dim reader as XmlReader = XmlReader.Create("http://ServerName/data/books.xml", settings)
C#
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Set the reader settings object to use the resolver.
settings.XmlResolver = resolver;

// Create the XmlReader object.
XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);
Visual C++
// Create a resolver with default credentials.
XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
resolver->Credentials = System::Net::CredentialCache::DefaultCredentials;

 // Set the reader settings object to use the resolver.
 settings->XmlResolver = resolver;

// Create the XmlReader object.
XmlReader^ reader = XmlReader::Create( L"http://ServerName/data/books.xml", settings );

CPP_OLD
// Create a resolver with default credentials.
XmlUrlResolver* resolver = new XmlUrlResolver();
resolver->Credentials = System::Net::CredentialCache::DefaultCredentials;

// Create the XmlReader object.
XmlReader* reader = XmlReader::Create(S"http://ServerName/data/books.xml", 0, resolver, settings);
See Also

Reference

Tags :


Page view tracker