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();

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

© 2014 Microsoft