控制 XML 序列化的屬性Attributes That Control XML Serialization

您可以將下表中的屬性套用到類別和類別成員,以便控制 XmlSerializer 序列化或還原序列化類別之執行個體的方式。You can apply the attributes in the following table to classes and class members to control the way in which the XmlSerializer serializes or deserializes an instance of the class. 若要了解這些屬性如何控制 XML 序列化,請參閱使用屬性控制 XML 序列化To understand how these attributes control XML serialization, see Controlling XML Serialization Using Attributes.

這些屬性也可用來控制 XML Web Service 產生的常值樣式 SOAP 訊息。These attributes can also be used to control the literal style SOAP messages generated by an XML Web service. 如需將這些屬性套用至 XML Web Service 方法的詳細資訊,請參閱以 XML Web Service 進行 XML 序列化For more information about applying these attributes to an XML Web services method, see XML Serialization with XML Web Services.

如需屬性的詳細資訊,請參閱屬性For more information about attributes, see Attributes.

屬性Attribute 適用於Applies to 指定Specifies
XmlAnyAttributeAttribute 公用欄位、屬性、參數或傳回 XmlAttribute 物件陣列的傳回值。Public field, property, parameter, or return value that returns an array of XmlAttribute objects. 當還原序列化時,陣列將填入代表所有結構描述未知之 XML 屬性的 XmlAttribute 物件。When deserializing, the array will be filled with XmlAttribute objects that represent all XML attributes unknown to the schema.
XmlAnyElementAttribute 公用欄位、屬性、參數或傳回 XmlElement 物件陣列的傳回值。Public field, property, parameter, or return value that returns an array of XmlElement objects. 當還原序列化時,陣列將填入代表所有結構描述未知之 XML 項目的 XmlElement 物件。When deserializing, the array is filled with XmlElement objects that represent all XML elements unknown to the schema.
XmlArrayAttribute 公用欄位、屬性、參數或傳回複雜物件陣列的傳回值。Public field, property, parameter, or return value that returns an array of complex objects. 陣列的成員將產生為 XML 陣列的成員。The members of the array will be generated as members of an XML array.
XmlArrayItemAttribute 公用欄位、屬性、參數或傳回複雜物件陣列的傳回值。Public field, property, parameter, or return value that returns an array of complex objects. 可插入陣列的衍生型別。The derived types that can be inserted into an array. 通常與 XmlArrayAttribute 一起套用。Usually applied in conjunction with an XmlArrayAttribute.
XmlAttributeAttribute 公用欄位、屬性、參數或傳回值。Public field, property, parameter, or return value. 成員將會序列化成 XML 屬性。The member will be serialized as an XML attribute.
XmlChoiceIdentifierAttribute 公用欄位、屬性、參數或傳回值。Public field, property, parameter, or return value. 使用列舉型別可進一步明確識別成員。The member can be further disambiguated by using an enumeration.
XmlElementAttribute 公用欄位、屬性、參數或傳回值。Public field, property, parameter, or return value. 欄位或屬性將序列化成 XML 項目。The field or property will be serialized as an XML element.
XmlEnumAttribute 為列舉識別項的公用欄位。Public field that is an enumeration identifier. 列舉成員的項目名稱。The element name of an enumeration member.
XmlIgnoreAttribute 公用屬性與欄位。Public properties and fields. 所屬類別序列化時,略過屬性或欄位。The property or field should be ignored when the containing class is serialized.
XmlIncludeAttribute 公用衍生類別宣告以及 Web 服務描述語言 (WSDL) 文件的公用方法傳回值。Public derived class declarations, and return values of public methods for Web Services Description Language (WSDL) documents. 當產生結構描述時應包含類別 (在序列化時辨認)。The class should be included when generating schemas (to be recognized when serialized).
XmlRootAttribute 公用類別宣告Public class declarations. 控制做為 XML 根項目之屬性目標的 XML 序列化。Controls XML serialization of the attribute target as an XML root element. 請使用屬性更進一步指定命名空間與項目名稱。Use the attribute to further specify the namespace and element name.
XmlTextAttribute 公用屬性與欄位。Public properties and fields. 屬性或欄位應序列化成 XML 文字。The property or field should be serialized as XML text.
XmlTypeAttribute 公用類別宣告Public class declarations. XML 型別的名稱與命名空間。The name and namespace of the XML type.

除了這些在 System.Xml.Serialization 命名空間都找得到的屬性之外,您也可以對欄位套用 DefaultValueAttribute 屬性。In addition to these attributes, which are all found in the System.Xml.Serialization namespace, you can also apply the DefaultValueAttribute attribute to a field. 如果未指定任何值,DefaultValueAttribute 會設定將自動指派給成員的值。The DefaultValueAttribute sets the value that will be automatically assigned to the member if no value is specified.

若要控制編碼的 SOAP XML 序列化,請參閱控制編碼 SOAP 序列化的屬性To control encoded SOAP XML serialization, see Attributes That Control Encoded SOAP Serialization.

另請參閱See also