XmlSchemaSet.Add Method (XmlSchemaSet)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Adds all the XML Schema definition language (XSD) schemas in the given XmlSchemaSet to the XmlSchemaSet.

Namespace:   System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

Public Sub Add (
	schemas As XmlSchemaSet


Type: System.Xml.Schema.XmlSchemaSet

The XmlSchemaSet object.

Exception Condition

A schema in the XmlSchemaSet is not valid.


The XmlSchemaSet object passed as a parameter is null.

Before a schema can be added to an XmlSchemaSet, it has to be successfully preprocessed. Preprocessing performs the following basic tasks.

  1. The schema is checked for structural validity according to the rules of W3C XML Schema, but the schema is not fully validated.

  2. References to internal and external schema components are resolved. Any imported or included schemas that are successfully retrieved are also added to the XmlSchemaSet. Imported schemas are added as separate XmlSchema objects, and included schemas are made a part of the including XmlSchema.

If the IsCompiled property of the XmlSchemaSet to add is true, all schemas in the XmlSchemaSet to add are added to the XmlSchemaSet. If the IsCompiled property of the XmlSchemaSet to add is false, each schema added is preprocessed before being added. If any of the schemas in the newly added XmlSchemaSet fails to be preprocessed, no schemas are added; instead, an XmlSchemaException is thrown. As a result, the following two code example are not equivalent.

' First example

' Second example
Dim schema As XmlSchema

For Each schema in schemaSet.Schemas()



The previous two code examples are not equivalent. In the first example, if an invalid schema exists in schemaSet1 and its IsCompiled property is set to false, no schemas are added to schemaSet. In the second example, a number of schemas can be added to schemaSet before an invalid schema is encountered and an exception is thrown.

The following code example illustrates adding schemas to an XmlSchemaSet, then adding the XmlSchemaSet to a new XmlSchemaSet using the Add method.

Dim schemaSet1 As XmlSchemaSet = New XmlSchemaSet
schemaSet1.Add("http://www.contoso.com/retail", "http://www.contoso.com/retail.xsd")
schemaSet1.Add("http://www.contoso.com/books", "http://www.contoso.com/books.xsd")
schemaSet1.Add("http://www.contoso.com/music", "http://www.contoso.com/music.xsd")

Dim schemaSet2 As XmlSchemaSet = New XmlSchemaSet

.NET Framework
Available since 2.0
Return to top