Schema Object Model Overview

The Schema Object Model (SOM) provides a set of classes in the System.Xml.Schema namespace that corresponds to and fully complies with the World Wide Web Consortium (W3C) XML Schema Recommendation. These classes allow you to read a schema from a file, or programmatically create a schema in memory that can be compiled and validated or can be written to a file.

The SOM provides the following features:

  • Loads and saves valid XML Schema definition language (XSD) schemas to and from files.
  • Provides an easy way to create in-memory schemas using strongly typed classes.
  • Interacts with the XmlSchemaCollection class to cache and retrieve schemas.
  • Interacts with the XmlValidatingReader class (through the XmlSchemaCollection class) to validate XML instance documents against schemas.
  • Enables tool developers to build editors for creating and maintaining schemas.
  • Provides the ability to dynamically edit a schema that can be complied and saved for use in the validation of XML instance documents.

The classes in the System.Xml.Schema namespace complement the parse-time validation performed by the XmlValidatingReader.

The XmlSchema class builds a SOM programmatically using the classes in the System.Xml.Schema namespace. The SOM conforms to the rules of writing well-formed XML documents outlined in the W3C Extensible Markup Language (XML) 1.0 Recommendation. The SOM edits XML Schema definition language (XSD) documents in a way that is similar to the way the Document Object Model (DOM) edits XML documents.

The XmlSchema class validates XML Schemas and rebuilds the validation information, the post-schema-validation infoset that is held for the schema.

You can validate any programmatically built schema using the Compile method of the XmlSchema class. The Compile method is used to verify that the schema is semantically correct. For example, the Compile method checks that the XML Schema structure is correct, verifies that the constraints are correctly applied, and that the types are derived correctly.

During validation, a validation callback is used if the parser produces a warning or error. The ValidationEventHandler for the Compile method is used for semantic validation checking of XML Schema.

In addition to building schemas, you can also load schemas from a file using the XmlSchema.Read method. The ValidationEventHandler is called when any syntactic or semantic validation errors occur during a read with the XmlSchema.Read method. For more information, see XmlValidatingReader Validation Event Handler Callback.

SOM Hierarchy

The following diagram illustrates the Schema Object Model (SOM) class hierarchy.

Schema Object Model (SOM) class hierarchy

1yce79bk.xmlschemanamespacemaster(en-us,VS.71).gif

See Also

XML Schema Object Model (SOM) | XML Schema Reference (XSD) | Validation of XML with Schemas