XmlSchemaSet.RemoveRecursive(XmlSchema) Metod

Definition

Tar bort det angivna XSD-schemat (XML Schema Definition Language) och alla scheman som det importerar från 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

Parametrar

schemaToRemove
XmlSchema

Objektet XmlSchema som ska tas bort från XmlSchemaSet.

Returer

trueom objektet XmlSchema och alla dess importer har tagits bort, annars . false

Undantag

Den XmlSchema som skickas som en parameter är null.

Exempel

I följande kodexempel visas hur du lägger till flera scheman i ett XmlSchemaSetoch sedan tar bort ett av schemana och alla scheman som importeras med hjälp av RemoveRecursive metoden.

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);
    }
}

Kommentarer

Metoden RemoveRecursive tar bort det angivna schemat och alla scheman som importeras från XmlSchemaSet, så länge det inte finns några beroenden för schemat eller dess importerade scheman. Om det finns beroenden för schemat eller dess importerade scheman XmlSchemaSeti tas ingenting bort och RemoveRecursive returnerar false. Om false returneras och en ValidationEventHandler definieras skickas en varning till händelsehanteraren som beskriver beroendena.

Om det angivna schemat importerar andra scheman och det angivna schemat tidigare har tagits bort med Remove metoden tar RemoveRecursive metoden inte bort de importerade schemana och returnerar false. Om importer och följande kod till exempel parentSchema bara tar bort childSchema1, men inte importerade childSchema2 och parentSchema scheman:childSchema1childSchema2

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();

Följande kod tar bort parentSchema och importerade scheman:

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

Metoden RemoveRecursive har ingen effekt på egenskapens IsCompiled tillstånd.

Gäller för