This documentation is archived and is not being maintained.

XmlSchemaSet.Add Method (XmlSchemaSet)

Note: This method is new in the .NET Framework version 2.0.

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
)

Parameters

schemas

The XmlSchemaSet object.

Exception typeCondition

XmlSchemaException

A schema in the XmlSchemaSet is not valid.

ArgumentNullException

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
schemaSet.Add(schemaSet1);

// Second example
foreach(XmlSchema schema in schemaSet.Schemas())
{
    schemaSet.Add(schema);
}

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();
schemaSet2.Add(schemaSet1);

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0
Show: