XmlAttributeAttribute.DataType 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置 XmlSerializer 生成的 XML 属性的 XSD 数据类型。
public:
 property System::String ^ DataType { System::String ^ get(); void set(System::String ^ value); };public string DataType { get; set; }member this.DataType : string with get, setPublic Property DataType As String属性值
XSD (XML 架构文档) 数据类型。
示例
以下示例将应用于 XmlAttributeAttribute 两个成员,并将 DataType 属性集设置为不同的值。
public ref class Group
{
public:
   [XmlAttributeAttribute(DataType="string")]
   String^ Name;
   [XmlAttributeAttribute(DataType="base64Binary")]
   array<Byte>^Hex64Code;
};
public class Group{
   [XmlAttribute(DataType = "string")]
   public string Name;
    
   [XmlAttribute (DataType = "base64Binary")]
   public byte[] Hex64Code;
}
public class Group
    <XmlAttribute(DataType := "string")> _
    public Name As string 
    <XmlAttribute (DataType := "base64Binary")> _
    public Hex64Code () As byte 
End Class
注解
下表列出了具有 their.NET 等效项的 XSD 简单数据类型。
对于 XSD base64Binary 和hexBinary数据类型,请使用结构数组Byte,并根据需要将XmlArrayItemAttributeDataType属性集应用于“base64Binary”或“hexBinary”。 对于 XSD time 和date数据类型,请使用该DateTime类型,并将集DataType应用于XmlAttributeAttribute“date”或“time”。
对于映射到字符串的每个 XSD 类型,应用 XmlAttributeAttribute 其 DataType 属性设置为 XSD 类型。 但是,这不会更改序列化格式,仅更改成员的架构。
备注
该属性区分大小写,因此必须将其完全设置为 XSD 数据类型之一。
备注
将二进制数据作为 XML 元素传递比将其作为 XML 属性传递更有效。
有关 XML 数据类型的详细信息,请参阅万维网联盟中的 XML 架构第 2 部分:DataTypes 文档。
| XSD 数据类型 | .NET 数据类型 | 
|---|---|
| anyURI | String | 
| base64Binary | Byte 对象的数组 | 
| boolean | Boolean | 
| 字节 | SByte | 
| 日期 | DateTime | 
| dateTime | DateTime | 
| Decimal | Decimal | 
| Double | Double | 
| ENTITY | String | 
| 实体 | String | 
| FLOAT | Single | 
| gDay | String | 
| gMonth | String | 
| gMonthDay | String | 
| gYear | String | 
| gYearMonth | String | 
| hexBinary | Byte 对象的数组 | 
| ID | String | 
| IDREF | String | 
| IDREFS | String | 
| int | Int32 | 
| 整型 | String | 
| 语言 | String | 
| long | Int64 | 
| “属性” | String | 
| NCName | String | 
| negativeInteger | String | 
| NMTOKEN | String | 
| NMTOKENS | String | 
| normalizedString | String | 
| nonNegativeInteger | String | 
| nonPositiveInteger | String | 
| NOTATION | String | 
| positiveInteger | String | 
| QName | XmlQualifiedName | 
| duration | String | 
| 字符串 | String | 
| short | Int16 | 
| time | DateTime | 
| 令牌 | String | 
| unsignedByte | Byte | 
| unsignedInt | UInt32 | 
| unsignedLong | UInt64 | 
| unsignedShort | UInt16 |