XmlSchemaSet.RemoveRecursive(XmlSchema) XmlSchemaSet.RemoveRecursive(XmlSchema) XmlSchemaSet.RemoveRecursive(XmlSchema) XmlSchemaSet.RemoveRecursive(XmlSchema) Method

定义

XmlSchemaSet 中移除指定的 XML 架构定义语言 (XSD) 架构和它导入的所有架构。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

参数

schemaToRemove
XmlSchema XmlSchema XmlSchema XmlSchema

要从 XmlSchema 中移除的 XmlSchemaSet 对象。The XmlSchema object to remove from the XmlSchemaSet.

返回

如果已成功移除 XmlSchema 对象和其导入的所有内容,则为 true;否则为 falsetrue if the XmlSchema object and all its imports were successfully removed; otherwise, false.

异常

作为参数传递的 XmlSchemanullThe XmlSchema passed as a parameter is null.

示例

下面的代码示例演示了添加到多个架构XmlSchemaSet,然后删除其中一个架构和它导入使用的所有架构RemoveRecursive方法。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);  
    }  
}  

注解

RemoveRecursive方法中删除指定的架构和它中导入的所有架构XmlSchemaSet,只要在该架构或其导入的架构上没有依赖项。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. 是否有架构或其导入的架构中的依赖项XmlSchemaSet,没有删除任何内容并RemoveRecursive返回falseIf there are dependencies on the schema or its imported schemas in the XmlSchemaSet, nothing is removed and RemoveRecursive returns false. 如果false返回和ValidationEventHandler是定义,描述依赖项的事件处理程序发送一条警告。If false is returned and a ValidationEventHandler is defined, a warning is sent to the event handler describing the dependencies.

如果指定的架构将其他架构导入,并且以前已移除指定的架构Remove方法,RemoveRecursive方法将不会删除导入的架构,并将返回falseIf 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. 例如,如果parentSchema导入childSchema1childSchema2下面的代码只会删除parentSchema,但未导入childSchema1childSchema2架构: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();  

下面的代码将删除parentSchema和导入的架构: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();  

RemoveRecursive方法不起作用的状态IsCompiled属性。The RemoveRecursive method has no effect on the state of the IsCompiled property.

适用于