System.XmlSchema Class
Namespace: System.Xml.Schema
Assembly: System.Xml.dll
The XmlSchema class provides a representation of an XML Schema definition language (XSD) schema. It allows you to load, compile, and work with XSD schemas programmatically.
Syntax
public class XmlSchema : XmlSchemaObject
Members
Properties
Attributes– Collection of global attribute declarations.Elements– Collection of global element declarations.TargetNamespace– The target namespace of the schema.Includes– Included or imported schemas.
Methods
Compile(ValidationEventHandler validationEventHandler)– Compiles the schema.Write(XmlWriter writer)– Writes the schema to anXmlWriter.
Events
ValidationEventHandler– Raised when a validation error occurs.
Example
using System;
using System.Xml;
using System.Xml.Schema;
class Program
{
static void Main()
{
XmlSchema schema = XmlSchema.Read(
XmlReader.Create("person.xsd"),
ValidationEventHandler);
schema.Compile(ValidationEventHandler);
Console.WriteLine("Schema compiled successfully.");
}
static void ValidationEventHandler(object sender, ValidationEventArgs e)
{
Console.WriteLine($"{e.Severity}: {e.Message}");
}
}