Redigera

Dela via


XmlSchemaSet.RemoveRecursive(XmlSchema) Method

Definition

Removes the specified XML Schema definition language (XSD) schema and all the schemas it imports from the XmlSchemaSet.

public:
 bool RemoveRecursive(System::Xml::Schema::XmlSchema ^ schemaToRemove);
public bool RemoveRecursive (System.Xml.Schema.XmlSchema schemaToRemove);
member this.RemoveRecursive : System.Xml.Schema.XmlSchema -> bool
Public Function RemoveRecursive (schemaToRemove As XmlSchema) As Boolean

Parameters

schemaToRemove
XmlSchema

The XmlSchema object to remove from the XmlSchemaSet.

Returns

true if the XmlSchema object and all its imports were successfully removed; otherwise, false.

Exceptions

The XmlSchema passed as a parameter is null.

Examples

The following code example illustrates adding multiple schemas to an XmlSchemaSet, then removing one of the schemas and all the schemas it imports using the RemoveRecursive method.

Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
schemaSet.Add("http://www.contoso.com/retail", "http://www.contoso.com/retail.xsd")
schemaSet.Add("http://www.contoso.com/books", "http://www.contoso.com/books.xsd")
schemaSet.Add("http://www.contoso.com/music", "http://www.contoso.com/music.xsd")

Dim schema As XmlSchema

For Each schema In schemaSet.Schemas()

    If schema.TargetNamespace = "http://www.contoso.com/music" Then
        schemaSet.RemoveRecursive(schema)
    End If

Next
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("http://www.contoso.com/retail", "http://www.contoso.com/retail.xsd");
schemaSet.Add("http://www.contoso.com/books", "http://www.contoso.com/books.xsd");
schemaSet.Add("http://www.contoso.com/music", "http://www.contoso.com/music.xsd");

foreach (XmlSchema schema in schemaSet.Schemas())
{
    if (schema.TargetNamespace == "http://www.contoso.com/music")
    {
        schemaSet.RemoveRecursive(schema);
    }
}

Remarks

The RemoveRecursive method removes the specified schema and all the schemas it imports from the XmlSchemaSet, as long as there are no dependencies on the schema or its imported schemas. If there are dependencies on the schema or its imported schemas in the XmlSchemaSet, nothing is removed and RemoveRecursive returns false. If false is returned and a ValidationEventHandler is defined, a warning is sent to the event handler describing the dependencies.

If the specified schema imports other schemas and the specified schema was previously removed with the Remove method, the RemoveRecursive method will not remove the imported schemas and will return false. For example, if parentSchema imports childSchema1 and childSchema2 the following code will only remove parentSchema, but not the imported childSchema1 and childSchema2 schemas:

XmlSchemaSet ss = new XmlSchemaSet();
XmlSchema xs = XmlSchema.Read(XmlReader.Create("parentSchema.xsd"), null);
ss.Add(xs);
ss.Compile();
ss.Remove(xs);
ss.Compile();
ss.RemoveRecursive(xs);
ss.Compile();

The following code will remove the parentSchema and the imported schemas:

XmlSchemaSet ss = new XmlSchemaSet();
XmlSchema xs = XmlSchema.Read(XmlReader.Create("parentSchema.xsd"), null);
ss.Add(xs);
ss.Compile();
ss.RemoveRecursive(xs);
ss.Compile();

The RemoveRecursive method has no effect on the state of the IsCompiled property.

Applies to