XmlSchemaSet.Compile 方法


將加入至 XmlSchemaSet 的 XML 結構描述定義語言 (XSD) 結構描述,編譯為一個邏輯結構描述。Compiles the XML Schema definition language (XSD) schemas added to the XmlSchemaSet into one logical schema.

 void Compile();
public void Compile ();
member this.Compile : unit -> unit
Public Sub Compile ()


錯誤發生於驗證和編譯 XmlSchemaSet 中的結構描述時。An error occurred when validating and compiling the schemas in the XmlSchemaSet.


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


這個方法會在需要驗證時自動呼叫,而且先前尚未編譯 XmlSchemaSet-例如,當 XmlSchemaSet 做為輸入,以在 XmlReaderSettings 物件的 Schemas 屬性中建立 XmlReader 物件時。This method is called automatically when validation is needed and the XmlSchemaSet has not been previously compiled - for example, when an XmlSchemaSet is used as an input to create an XmlReader object in the Schemas property of an XmlReaderSettings object. 如果 XmlSchemaSet 已經是已編譯的狀態,這個方法將不會重新編譯架構。If the XmlSchemaSet is already in the compiled state, this method will not recompile the schemas. 如果這個方法順利執行,IsCompiled 屬性會設定為 trueIf this method executes successfully, the IsCompiled property is set to true.

先前由 XmlSchemaSet 編譯的架構不會重新編譯。Schemas that have been previously compiled by an XmlSchemaSet are not recompiled. 不過,使用 XmlSchemaCompile 方法編譯的架構將會重新編譯。However, schemas that were compiled using the Compile method of the XmlSchema will be recompiled.


如果您已在將架構(或它的其中一個包含/匯入)新增至 XmlSchemaSet之後,變更它,則需要呼叫 Reprocess 方法。You need to call the Reprocess method if you have changed a schema (or one of its includes/imports) after adding it to the XmlSchemaSet. Reprocess 方法會根據 W3C XML 架構的規則,檢查架構的結構有效性。The Reprocess method will check the schema for structural validity according to the rules of W3C XML Schema. 不過,它不會執行完整的驗證檢查。However, it will not perform a full validation check. 它也會解析對內部和外部架構元件的參考。It will also resolve references to internal and external schema components. 任何成功取得的匯入或包含的架構也會新增至 XmlSchemaSetAny imported or included schemas that are successfully retrieved are also added to the XmlSchemaSet. 匯入的架構會新增為個別的 XmlSchema 物件,而包含的架構則會成為包含 XmlSchema的一部分。Imported schemas are added as separate XmlSchema objects while included schemas are made part of the including XmlSchema. 如果重新處理的呼叫成功,IsCompiled 屬性會設定為 false。If the call to reprocess is successful, the IsCompiled property is set to false.