XML 和 SOAP 序列化XML and SOAP Serialization

XML 序列化将对象的公共字段和属性或者方法的参数及返回值转换(序列化)为符合特定 XML 架构定义语言 (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 序列化会生成强类型类,同时将公共属性和字段转换为序列格式(在此情况下为 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 services 使用 XmlSerializer 类来创建 XML 流,这些流在整个 Internet 中或在 Intranet 上的 XML Web services 应用程序之间传递数据。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 services 进行 XML 序列化XML Serialization with XML Web Services
说明如何在 XML Web services 中使用 XML 序列化。Explains how XML serialization is used in XML Web services.

如何:将对象序列化为 SOAP 编码的 XML StreamHow to: Serialize an Object as a SOAP-Encoded XML Stream
介绍如何使用XmlSerializer类,以创建编码的 SOAP XML 流符合到第 5 节的 World Wide Web 联合会 (W3C) 文档简单对象访问协议 (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 Service 客户端XML Web Services Created Using ASP.NET and XML Web Service Clients
提供一些主题,描述并说明如何使用 ASP.NET 对 XML Web services 进行编程。Provides topics that describe and explain how to program XML Web services using ASP.NET.

请参阅See also