Namespace Summary
The System.Xml.Schema namespace contains the XML Schema definition language (XSD) implementation, which provides classes that enable you to create, edit, validate and navigate through XML Schemas.
Key Classes
| Class | Description |
|---|---|
| XmlReader | Provides a fast, non-cached, forward-only way of reading XML data. |
| XmlReaderSettings | Specifies a set of features to support on the XmlReader object created by the Create method. |
| XmlSchema | Represents an XML Schema definition language (XSD) schema. |
| XmlValidatingReader | Validates XML data using XML Schemas or DTDs while reading. |
Sample Code
using System;
using System.Xml;
using System.Xml.Schema;
class Program
{
static void Main()
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, "example.xsd");
settings.ValidationEventHandler += (sender, e) =>
{
Console.WriteLine($"Validation {e.Severity}: {e.Message}");
};
using (XmlReader reader = XmlReader.Create("example.xml", settings))
{
while (reader.Read()) { }
}
}
}