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方法将不会删除导入的false架构并且将返回。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. parentSchema例如, 如果 imports 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.

适用于