Adds the XML Schema definition language (XSD) schema contained in the System.Xml.XmlReader to the System.Xml.Schema.XmlSchemaSet.
- targetNamespace
- The schema targetNamespace property, or null to use the targetNamespace specified in the schema.
- schemaDocument
- The System.Xml.XmlReader object.
An System.Xml.Schema.XmlSchema object if the schema is valid. If the schema is not valid and a System.Xml.Schema.ValidationEventHandler is specified, then null is returned and the appropriate validation event is raised. Otherwise, an System.Xml.Schema.XmlSchemaException is thrown.
Before a schema can be added to an System.Xml.Schema.XmlSchemaSet, it has to be successfully preprocessed. Preprocessing performs the following basic tasks.
[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]The following are important notes to consider when using the XmlSchemaSet.Add(string, System.Xml.XmlReader) method.
Successfully retrieved schemas imported or included by the schemas contained in the System.Xml.XmlReader are also added to the System.Xml.Schema.XmlSchemaSet.
If the System.Xml.XmlReader is not positioned on the root element, an System.Xml.Schema.XmlSchemaException is thrown unless the current item is an element. If the current item is an xs:schema element, the schema document is read into the System.Xml.Schema.XmlSchemaSet; otherwise, an System.Xml.Schema.XmlSchemaException is thrown because the schema is not valid.
If the System.Xml.XmlReader is positioned over a sequence of XML nodes, only the first node in the sequence is added.
If the schema was created from a erload:System.Xml.XmlReader.Create method call, the value of the XmlSchemaValidationFlags.ProcessInlineSchema property is ignored, because inline schema processing is not applied for W3C XML Schema documents.
The System.Xml.XmlResolver property of the System.Xml.XmlReader is not used to resolve references to namespaces or schema locations in include and import elements. Instead, the System.Xml.XmlResolver property of the System.Xml.Schema.XmlSchemaSet is used.
The XmlSchemaSet.Add(string, System.Xml.XmlReader) method of the System.Xml.Schema.XmlSchemaSet has the ability to use the target namespace defined in a schema, rather than requiring the target namespace be specified as a parameter when the XmlSchemaSet.Add(string, System.Xml.XmlReader) method is called. Specifying null or string.Empty to the XmlSchemaSet.Add(string, System.Xml.XmlReader) method instructs the System.Xml.Schema.XmlSchemaSet to use the target namespace defined in the schema. For an example of this behavior, see the XmlSchemaSet.Add(string, string) method.
The remaining functionality of this method is identical to that of the XmlSchemaSet.Add(string, string) method.