See Also: XmlSchemaSet Members
In System.Xml version 1.0, XML schemas were loaded into an System.Xml.Schema.XmlSchemaCollection class as a library of schemas. In System.Xml version 2.0, the System.Xml.XmlValidatingReader and the System.Xml.Schema.XmlSchemaCollection classes are obsolete, and have been replaced by the erload:System.Xml.XmlReader.Create method and the System.Xml.Schema.XmlSchemaSet class, respectively.
The System.Xml.Schema.XmlSchemaSet has been introduced to fix a number of issues, including standards compatibility, performance, and the obsolete Microsoft XML-Data Reduced (XDR) schema format.
The following is a comparison between the System.Xml.Schema.XmlSchemaCollection class and the System.Xml.Schema.XmlSchemaSet class.
Supports Microsoft XDR and W3C XML schemas. |
Only supports W3C XML schemas. |
Schemas are compiled when the erload:System.Xml.Schema.XmlSchemaCollection.Add method is called. |
Schemas are not compiled when the erload:System.Xml.Schema.XmlSchemaSet.Add method is called. This provides a performance improvement during creation of the schema library. |
Each schema generates an individual compiled version that can result in "schema islands." As a result, all includes and imports are scoped only within that schema. |
Compiled schemas generate a single logical schema, a "set" of schemas. Any imported schemas within a schema that are added to the set are directly added to the set themselves. This means that all types are available to all schemas. |
Only one schema for a particular target namespace can exist in the collection. |
Multiple schemas for the same target namespace can be added as long as there are no type conflicts. |
External namespaces or locations referenced in include, import, and redefine elements of a schema are resolved with respect to the base URI of the schema that includes or imports them. For example, if the base URI of the including or importing schema is empty or null, the external locations are resolved with respect to the current directory. The System.Xml.XmlUrlResolver class is used to resolve external schemas by default. To disable resolution of include, import, and redefine elements of a schema, set the XmlSchemaSet.XmlResolver property to null.
The System.Xml.Schema.XmlSchemaSet class uses the System.Text.RegularExpressions.Regex class to parse and match regular expressions in an XML schema. Validation of pattern facets with regular expressions in an XML schema may involve increased CPU usage and should be avoided in high availability scenarios.
Exceptions raised as a result of using the System.Xml.Schema.XmlSchemaSet class, such as the System.Xml.Schema.XmlSchemaException class may contain sensitive information that should not be exposed in untrusted scenarios. For example, the XmlSchemaException.SourceUri property of an System.Xml.Schema.XmlSchemaException returns the URI path to the schema file that caused the exception. The XmlSchemaException.SourceUri property should not be exposed in untrusted scenarios. Exceptions should be properly handled so that this sensitive information is not exposed in untrusted scenarios.