XmlSchemaSet.RemoveRecursive(XmlSchema) 方法

定義

移除 XmlSchemaSet 中指定的 XML 結構描述定義語言 (XSD) 結構描述及其匯入的所有結構描述。

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 中移除的 XmlSchemaSet 物件。

傳回

如果成功移除 XmlSchema 物件及其匯入的所有結構描述,則為 true,否則為 false

例外狀況

以參數形式傳遞的 XmlSchema 物件為 null

範例

下列程式碼範例說明如何將多個架構新增至 XmlSchemaSet ,然後使用 方法移除其中一個架構及其匯入 RemoveRecursive 的所有架構。

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 匯入的所有架構,只要架構或其匯入的架構沒有相依性即可。 如果 中的架構或其匯入的架構 XmlSchemaSet 有相依性,則不會移除任何專案並 RemoveRecursivefalse 回 。 如果 false 傳回 並定義 , ValidationEventHandler 則會將警告傳送至描述相依性的事件處理常式。

如果指定的架構匯入其他架構,而且先前已使用 Remove 方法移除指定的架構, RemoveRecursive 則方法不會移除匯入的架構,而且會傳回 false 。 例如,如果 parentSchema 匯入 childSchema1childSchema2 下列程式碼只會移除 ,但不會移除 parentSchema 匯入 childSchema1 的 和 childSchema2 架構:

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 和 匯入的架構:

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

適用於