Adds the schema contained in the System.Xml.XmlReader to the schema collection.
- ns
- The namespace URI associated with the schema. For XML Schemas, this will typically be the targetNamespace.
- reader
- System.Xml.XmlReader containing the schema to add.
The System.Xml.Schema.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.
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 System.Xml.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 System.Xml.XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.
Semi-trusted code: External references are not resolved.
If the XmlSchemaCollection is being accessed using the System.Xml.XmlValidatingReader.Schemas property, the Add method uses the XmlResolver specified by the System.Xml.XmlValidatingReader.XmlResolver property.
The System.Xml.Schema.XmlSchemaCollection class is obsolete in the .NET Framework version 2.0 and has been replaced by the System.Xml.Schema.XmlSchemaSet class.