Adds the XML Schema definition language (XSD) schema at the URL specified to the System.Xml.Schema.XmlSchemaSet.
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, string) method.
Adding a schema to the System.Xml.Schema.XmlSchemaSet with the same target namespace and schema location URL as a schema already contained within the System.Xml.Schema.XmlSchemaSet will return the original schema object.
When a new schema is successfully added to an System.Xml.Schema.XmlSchemaSet, the XmlSchemaSet.IsCompiled property of the System.Xml.Schema.XmlSchemaSet is set to false.
Any include or import elements encountered in an XML schema are resolved when the XmlSchemaSet.Add(string, string) method is called. Failure to resolve include and import elements results in a schema validation warning and if no XmlSchemaSet.ValidationEventHandler has been specified for the System.Xml.Schema.XmlSchemaSet object, these warning will not be reported.
If a schema with the same target namespace as a schema that already exists in the System.Xml.Schema.XmlSchemaSet is added to the System.Xml.Schema.XmlSchemaSet, both schemas are added.
The XmlSchemaSet.Add(string, string) 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, string) method is called. Specifying null in the targetNamespace parameter of the XmlSchemaSet.Add(string, string) method instructs the System.Xml.Schema.XmlSchemaSet to use the target namespace defined in the schema, as illustrated in the following code example.
Example
Dim schemaSet As XmlSchemaSet = New XmlSchemaSet() schemaSet.Add(Nothing, "books.xsd") Dim schema As XmlSchema For Each schema In schemaSet.Schemas("http://www.contoso.com/books") schema.Write(Console.Out) Next
Example
XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(null, "books.xsd"); foreach(XmlSchema schema in schemaSet.Schemas("http://www.contoso.com/books")) { schema.Write(Console.Out); }
In the code example above, null is specified as the targetNamespace parameter to the XmlSchemaSet.Add(string, string) method. As a result, the targetNamespace defined in the books.xml file is used. In this case, the result of calling the XmlSchemaSet.Add(string, string) method would be identical if http://www.contoso.com/books had been specified as the targetNamespace parameter.
W3C XML Schema allows schemas without a target namespace to be included in schemas with a target namespace defined. In this case, the schema without a target namespace defined is coerced into the target namespace of the including schema. The included schema is treated as if it had that target namespace defined. Similarly, schemas without a target namespace can be added to the System.Xml.Schema.XmlSchemaSet and coerced into the target namespace specified by the XmlSchemaSet.Add(string, string) method, as illustrated in the following example.
Example
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="A" type="xs:string" /> </xs:schema>
If the schema above is added to the System.Xml.Schema.XmlSchemaSet with the target namespace http://www.contoso.com/new/targetnamespace (as shown in the code below), it is treated as if the target namespace declared in the schema was http://www.contoso.com/new/targetnamespace.
Example
Dim schemaSet As XmlSchemaSet = New XmlSchemaSet() schemaSet.Add("http://www.contoso.com/new/targetnamespace", "http://www.contoso.com/targetnamespace.xsd") Dim schema As XmlSchema For Each schema in schemaSet.Schemas() Console.WriteLine(schema.TargetNamespace) Next
Example
XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add("http://www.contoso.com/new/targetnamespace", "http://www.contoso.com/targetnamespace.xsd"); foreach(XmlSchema schema in schemaSet.Schemas()) { Console.WriteLine(schema.TargetNamespace); }