XmlReaderSettings Class

Specifies a set of features to support on the XmlReader object created by the Create method.

System.Object
  System.Xml.XmlReaderSettings

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

[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public sealed class XmlReaderSettings

The XmlReaderSettings type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsXmlReaderSettings()Initializes a new instance of the XmlReaderSettings class.
Public methodXmlReaderSettings(XmlResolver) Obsolete. Initializes a new instance of the XmlReaderSettings class.
Top

  NameDescription
Public propertySupported in .NET for Windows Store appsAsyncGets or sets whether asynchronous XmlReader methods can be used on a particular XmlReader instance.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCheckCharactersGets or sets a value indicating whether to do character checking.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCloseInputGets or sets a value indicating whether the underlying stream or TextReader should be closed when the reader is closed.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsConformanceLevelGets or sets the level of conformance which the XmlReader will comply.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsDtdProcessingGets or sets a value that determines the processing of DTDs.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIgnoreCommentsGets or sets a value indicating whether to ignore comments.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIgnoreProcessingInstructionsGets or sets a value indicating whether to ignore processing instructions.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIgnoreWhitespaceGets or sets a value indicating whether to ignore insignificant white space.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLineNumberOffsetGets or sets line number offset of the XmlReader object.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLinePositionOffsetGets or sets line position offset of the XmlReader object.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsMaxCharactersFromEntitiesGets or sets a value indicating the maximum allowable number of characters in a document that result from expanding entities.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsMaxCharactersInDocumentGets or sets a value indicating the maximum allowable number of characters in an XML document. A zero (0) value means no limits on the size of the XML document. A non-zero value specifies the maximum size, in characters.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNameTableGets or sets the XmlNameTable used for atomized string comparisons.
Public propertyProhibitDtd Obsolete. Gets or sets a value indicating whether to prohibit document type definition (DTD) processing. This property is obsolete. Use DtdProcessing instead.
Public propertySupported by the XNA FrameworkSchemasGets or sets the XmlSchemaSet to use when performing schema validation.
Public propertySupported by the XNA FrameworkValidationFlagsGets or sets a value indicating the schema validation settings. This setting applies to XmlReader objects that validate schemas (ValidationType property set to ValidationType.Schema).
Public propertySupported by the XNA FrameworkValidationTypeGets or sets a value indicating whether the XmlReader will perform validation or type assignment when reading.
Public propertySupported by the XNA FrameworkXmlResolverSets the XmlResolver used to access external documents.
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCloneCreates a copy of the XmlReaderSettings instance.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsResetResets the members of the settings class to their default values.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventSupported by the XNA FrameworkValidationEventHandlerOccurs when the reader encounters validation errors.
Top

You use the Create method to obtain XmlReader instances. This method uses the XmlReaderSettings class to specify which features to implement in the XmlReader object it creates.

See the Remarks sections of the XmlReader and Create reference pages for information about which settings to use for conformance checks, validation, and other common scenarios. See the XmlReaderSettings() constructor for a list of default settings.

Security considerations

Consider the following when using the XmlReaderSettings class.

  • The ProcessInlineSchema and ProcessSchemaLocation validation flags of an XmlReaderSettings object are not set by default. When these flags are set, the XmlResolver of the XmlReaderSettings object is used to resolve schema locations encountered in the instance document in the XmlReader. If the XmlResolver object is null, schema locations are not resolved even if the ProcessInlineSchema and ProcessSchemaLocation validation flags are set.

  • Schemas added during validation add new types and can change the validation outcome of the document being validated. As a result, external schemas should only be resolved from trusted sources.

  • Validation error messages may expose sensitive content model information. Validation error and warning messages are handled using the ValidationEventHandler delegate, or are exposed as an XmlSchemaValidationException if no event handler is provided to the XmlReaderSettings object (validation warnings do not cause an XmlSchemaValidationException to be thrown). This content model information should not be exposed in untrusted scenarios. Validation warning messages are suppressed by default and can be reported by setting the ReportValidationWarnings flag.

  • The SourceUri property of an XmlSchemaValidationException returns the URI path to the schema file that caused the exception. The SourceUri property should not be exposed in untrusted scenarios.

  • Disabling the ProcessIdentityConstraints flag (enabled by default) is recommended when validating, untrusted, large XML documents in high availability scenarios against a schema with identity constraints over a large part of the document.

  • XmlReaderSettings objects can contain sensitive information such as user credentials. You should be careful when caching XmlReaderSettings objects, or when passing the XmlReaderSettings object from one component to another.

  • DTD processing is disabled by default. If you enable DTD processing, you need to be aware of including DTDs from untrusted sources and possible denial of service attacks. Use the XmlSecureResolver to restrict the resources that the XmlReader can access.

  • Do not accept supporting components, such as NameTable, XmlNamespaceManager, and XmlResolver objects, from an untrusted source.

  • Memory usage of an application that uses XmlReader may have a correlation to the size of the parsed XML document. One form of denial of service attack is when excessively large XML documents are submitted to be parsed. You can limit the size of the document that can be parsed by setting the MaxCharactersInDocument property and then limit the number of characters that result from expanding entities by setting the MaxCharactersFromEntities property.

The following example creates an XmlReader that uses an XmlUrlResolver with the necessary credentials.

// Create an XmlUrlResolver with the credentials necessary to access the Web server.
XmlUrlResolver resolver = new XmlUrlResolver();
System.Net.NetworkCredential myCred;
myCred  = new System.Net.NetworkCredential(UserName,SecurelyStoredPassword,Domain);  
resolver.Credentials = myCred;

XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = resolver;

// Create the reader.
XmlReader reader = XmlReader.Create("http://serverName/data/books.xml", settings);

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft