Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

XmlSchemaSet.Add Method (XmlSchemaSet)

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 void Add(
	XmlSchemaSet schemas


Type: System.Xml.Schema.XmlSchemaSet
The XmlSchemaSet object.


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
foreach(XmlSchema 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.

XmlSchemaSet schemaSet1 = 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");

XmlSchemaSet schemaSet2 = new XmlSchemaSet();

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft