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
public void Add (
	XmlSchemaSet schemas
public function Add (
	schemas : XmlSchemaSet
Not applicable.



The XmlSchemaSet object.

Exception typeCondition


A schema in the XmlSchemaSet is not valid.


The XmlSchemaSet object passed as a parameter is a null reference (Nothing in Visual Basic).

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions