XmlSchemaCollection.Add Method (String, XmlReader)

 

Adds the schema contained in the XmlReader to the schema collection.

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

public XmlSchema Add(
	string ns,
	XmlReader reader
)

Parameters

ns
Type: System.String

The namespace URI associated with the schema. For XML Schemas, this will typically be the targetNamespace.

reader
Type: System.Xml.XmlReader

XmlReader containing the schema to add.

Return Value

Type: System.Xml.Schema.XmlSchema

The XmlSchema added to the schema collection; null if the schema being added is an XDR schema or if there are compilation errors in the schema.

Exception Condition
XmlException

The schema is not a valid schema.

If ns has already been associated with another schema in the collection, the schema being added replaces the original schema in the collection.

If ns is null and the schema being added is an XML Schema, the Add method uses the targetNamespace defined in the XML Schema to identify the schema in the collection.

If the schema being added contains references to other namespaces (through include and import elements or the x-schema attribute), the trust level of the application determines how these other namespaces are resolved. (In the .NET Framework version 1.0, a default XmlUrlResolver was always used).

Fully trusted code: A default XmlUrlResolver with no user credentials is used to resolve any external resources. The schemas for these other namespaces are loaded for validation purposes only. Unlike the original schema, these other schemas are not explicitly added to the schema collection. As a result, they are not accessible using any of the collection methods or properties. If these external resources are located on a network resource that requires authentication, use an overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

Semi-trusted code: External references are not resolved.

System_CAPS_noteNote

If the XmlSchemaCollection is being accessed using the XmlValidatingReader.Schemas property, the Add method uses the XmlResolver specified by the XmlValidatingReader.XmlResolver property.

System_CAPS_importantImportant

The XmlSchemaCollection class is obsolete in the .NET Framework version 2.0 and has been replaced by the XmlSchemaSet class.

.NET Framework
Available since 1.1
Return to top
Show: