Class XmlReaderSettings
Represents the set of properties that can be used to configure an instance of XmlReader.
Table of Contents
Public Properties
| Name | Description |
|---|---|
| AsyncState | Gets or sets an object that contains state information for asynchronous operations. |
| CheckCharacters | Gets or sets a value indicating whether to check for characters that are not allowed in XML. |
| ConformanceLevel | Gets or sets a value indicating whether to check that the XML document conforms to the World Wide Web Consortium (W3C) XML 1.0 recommendation and conforms to the Document Type Definition (DTD). |
| DtdProcessing | Gets or sets a value indicating how to process the DTD. |
| IgnoreComments | Gets or sets a value indicating whether to ignore comments. |
| MaxAttributes | Gets or sets the maximum number of attributes allowed. |
| MaxElements | Gets or sets the maximum number of elements allowed. |
| NameTable | Gets or sets the XmlNameTable to use for atomizing names (element and attribute names). |
| ValidationFlags | Gets or sets a bitwise combination of ValidationFlags values. |
| ValidationType | Gets or sets a value indicating the type of validation to perform. |
| XmlResolver | Gets or sets the XmlResolver to use for resolving external XML resources. |
Public Constructors
| Name | Description |
|---|---|
| XmlReaderSettings() | Initializes a new instance of the XmlReaderSettings class with default settings. |
Public Methods
| Name | Description |
|---|---|
| Clone() | Creates a new object that is a copy of the current instance. |
| GetHashCode() | Returns the hash code for the current object. |
| GetType() | Gets the runtime type of the current instance. |
| ToString() | Returns a string that represents the current object. |
Remarks
The XmlReaderSettings class provides a way to configure the behavior of an XmlReader. You can specify settings such as whether to check for conformance to XML standards, how to process DTDs, whether to ignore comments, and more.
When you create an XmlReader, you can pass an instance of XmlReaderSettings to the constructor of XmlReader or to the Create method. If you do not specify any settings, the XmlReader will use default settings.
Here's a simple example of how to use XmlReaderSettings to create an XmlReader that ignores comments:
using System;
using System.Xml;
public class Example
{
public static void Main(string[] args)
{
string xmlString = @"<root>
<!-- This is a comment -->
<element>Some text</element>
</root>";
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(xmlString), settings))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "element")
{
reader.Read(); // Move to the text content
Console.WriteLine(reader.Value);
}
}
}
}
}
Requirements
Namespace: System.Xml
Assembly: System.Xml.dll