XML 和 SOAP 序列化XML and SOAP Serialization

XML 序列化會將物件的公用 (Public) 欄位和屬性,或是方法的參數和傳回值,轉換 (序列化) 為與特定 XML 結構描述 (Schema) 定義語言 (XSD) 文件相符的 XML 資料流。XML serialization converts (serializes) the public fields and properties of an object, or the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document. XML 序列化會產生強型別 (Strongly Typed) 類別,其中包含的公用屬性和欄位都轉換為序列格式 (此例為 XML) 以進行儲存或傳輸。XML serialization results in strongly typed classes with public properties and fields that are converted to a serial format (in this case, XML) for storage or transport.

因為 XML 為開放標準,無論是何種平台,XML 資料流都可依需要由任何應用程式處理。Because XML is an open standard, the XML stream can be processed by any application, as needed, regardless of platform. 例如,使用 ASP.NET 建立的 XML Web 服務以 XmlSerializer 類別建立 XML 資料流,在網際網路或內部網路的 XML Web 服務應用程式之間傳遞資料。For example, XML Web services created using ASP.NET use the XmlSerializer class to create XML streams that pass data between XML Web service applications throughout the Internet or on intranets. 相反地,還原序列化採用這樣的 XML 資料流並重建物件。Conversely, deserialization takes such an XML stream and reconstructs the object.

XML 序列化也可用來將物件序列化為與 SOAP 規格相符的 XML 資料流。XML serialization can also be used to serialize objects into XML streams that conform to the SOAP specification. SOAP 是以 XML 為基礎的通訊協定,特別設計來傳輸使用 XML 的程序呼叫。SOAP is a protocol based on XML, designed specifically to transport procedure calls using XML.

若要序列化或還原序列化物件,請使用 XmlSerializer 類別。To serialize or deserialize objects, use the XmlSerializer class. 若要建立要序列化的類別,請使用 XML 結構描述定義工具。To create the classes to be serialized, use the XML Schema Definition tool.

本節內容In This Section

XML 序列化簡介Introducing XML Serialization
提供序列化的一般定義,特別是 XML 序列化。Provides a general definition of serialization, particularly XML serialization.

如何:將物件序列化How to: Serialize an Object
提供序列化物件的逐步指示。Provides step-by-step instructions for serializing an object.

如何:還原序列化物件How to: Deserialize an Object
提供還原序列化物件的逐步指示。Provides step-by-step instructions for deserializing an object.

XML 序列化範例Examples of XML Serialization
提供範例示範 XML 序列化的基本概念。Provides examples that demonstrate the basics of XML serialization.

XML 結構描述定義工具和 XML 序列化The XML Schema Definition Tool and XML Serialization
說明如何使用 XML 結構描述定義工具,建立遵循特定 XML 結構描述定義語言 (XSD) 結構描述的類別,或是從 .dll 檔案產生 XML 結構描述。Describes how to use the XML Schema Definition tool to create classes that adhere to a particular XML Schema definition language (XSD) schema, or to generate an XML Schema from a .dll file.

使用屬性控制 XML 序列化Controlling XML Serialization Using Attributes
說明如何使用屬性控制序列化。Describes how to control serialization by using attributes.

可控制 XML 序列化的屬性Attributes That Control XML Serialization
列出用來控制 XML 序列化的屬性。Lists the attributes that are used to control XML serialization.

如何:指定 XML Stream 的替代項目名稱How to: Specify an Alternate Element Name for an XML Stream
提供進階案例展示如何藉由覆寫序列化產生多個 XML 資料流。Presents an advanced scenario showing how to generate multiple XML streams by overriding the serialization.

如何:控制序列化的衍生類別的How to: Control Serialization of Derived Classes
提供如何控制衍生類別序列化的範例。Provides an example of how to control the serialization of derived classes.

如何:限定 XML 元素和 XML 屬性名稱How to: Qualify XML Element and XML Attribute Names
說明如何定義並控制 XML 命名空間在 XML 資料流中使用的方式。Describes how to define and control the way in which XML namespaces are used in the XML stream.

以 XML Web 服務進行 XML 序列化XML Serialization with XML Web Services
說明 XML 序列化如何用於 XML Web 服務當中。Explains how XML serialization is used in XML Web services.

如何:將物件序列化為 SOAP 編碼的 XML StreamHow to: Serialize an Object as a SOAP-Encoded XML Stream
描述如何使用XmlSerializer類別來建立符合第 5 節的 World Wide Web Consortium (W3C) 文件的編碼的 SOAP XML 資料流簡易物件存取通訊協定 (SOAP) 1.1Describes how to use the XmlSerializer class to create encoded SOAP XML streams that conform to section 5 of the World Wide Web Consortium (W3C) document titled Simple Object Access Protocol (SOAP) 1.1.

如何:覆寫編碼的 SOAP XML 序列化How to: Override Encoded SOAP XML Serialization
說明將物件的 XML 序列化覆寫為 SOAP 訊息的程序。Describes the process for overriding XML serialization of objects as SOAP messages.

可控制編碼 SOAP 序列化的屬性Attributes That Control Encoded SOAP Serialization
列出用來控制 SOAP 編碼序列化的屬性。Lists the attributes that are used to control SOAP-encoded serialization.

<system.xml.serialization> 項目<system.xml.serialization> Element
用來控制 XML 序列化的最上層組態項目。The top-level configuration element for controlling XML serialization.

<dateTimeSerialization> 元素<dateTimeSerialization> Element
控制 DateTime 物件的序列化模式。Controls the serialization mode of DateTime objects.

<schemaImporterExtensions>元素<schemaImporterExtensions> Element
包含 XmlSchemaImporter 類別使用的類型。Contains types that are used by the XmlSchemaImporter class.

<新增 > 項目<schemaImporterExtensions ><add> Element for <schemaImporterExtensions>
新增 XmlSchemaImporter 類別使用的類型。Adds types that are used by the XmlSchemaImporter class.

使用 ASP.NET 和 XML Web Service 用戶端建立的 XML Web ServiceXML Web Services Created Using ASP.NET and XML Web Service Clients
提供一個主題,說明並解釋如何設計使用 ASP.NET 的 XML Web 服務。Provides topics that describe and explain how to program XML Web services using ASP.NET.

另請參閱See also