XmlAttributeAttribute.DataType 属性

定义

获取或设置 XmlSerializer 生成的 XML 属性的 XSD 数据类型。Gets or sets the XSD data type of the XML attribute generated by the XmlSerializer.

public:
 property System::String ^ DataType { System::String ^ get(); void set(System::String ^ value); };
public string DataType { get; set; }
member this.DataType : string with get, set
Public Property DataType As String

属性值

String

XSD (XML 架构文档) 数据类型。An XSD (XML Schema Document) data type.

示例

下面的示例将应用 XmlAttributeAttribute 到两个成员,并将 DataType 属性设置为不同的值。The following example applies the XmlAttributeAttribute to two members, and sets the DataType property set to different values.

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 简单数据类型。The following table lists the XSD simple data types with their.NET equivalents.

对于 XSD base64BinaryhexBinary 数据类型,请使用 Byte 结构数组,并 XmlArrayItemAttribute DataType 根据需要将属性设置为 "base64Binary" 或 "hexBinary" 的应用。For the XSD base64Binary and hexBinary data types, use an array of Byte structures, and apply a XmlArrayItemAttribute with the DataType property set to "base64Binary" or "hexBinary", as appropriate. 对于 XSD timedate 数据类型,请使用 DateTime 类型,并将 XmlAttributeAttribute DataType 设置为 "日期" 或 "时间"。For the XSD time and date data types, use the DateTime type and apply the XmlAttributeAttribute with the DataType set to "date" or "time".

对于映射到字符串的每个 XSD 类型,应用 XmlAttributeAttributeDataType 属性设置为 XSD 类型的。For every XSD type that is mapped to a string, apply the XmlAttributeAttribute with its DataType property set to the XSD type. 但是,这不会更改序列化格式,而只会更改成员的架构。However, this does not change the serialization format, only the schema for the member.

备注

属性区分大小写,因此必须将其精确设置为 XSD 数据类型之一。The property is case-sensitive, so you must set it exactly to one of the XSD data types.

备注

将二进制数据作为 XML 元素传递比将其作为 XML 特性传递更为有效。Passing binary data as an XML element is more efficient than passing it as an XML attribute.

有关 XML 数据类型的详细信息,请参阅 " Xml 架构第2部分: 来自万维网联合会的数据类型" 文档。For more information about XML data types, see the XML Schema Part 2: DataTypes document from the World Wide Web Consortium.

XSD 数据类型XSD data type .NET 数据类型.NET data type
anyURIanyURI String
base64Binarybase64Binary 对象数组 ByteArray of Byte objects
booleanboolean Boolean
字节byte SByte
日期date DateTime
dateTimedateTime DateTime
Decimaldecimal Decimal
Doubledouble Double
ENTITYENTITY String
条目ENTITIES String
FLOATfloat Single
gDaygDay String
gMonthgMonth String
gMonthDaygMonthDay String
gYeargYear String
gYearMonthgYearMonth String
hexBinaryhexBinary 对象数组 ByteArray of Byte objects
IDID String
IDREFIDREF String
IDREFSIDREFS String
intint Int32
整型integer String
语言language String
longlong Int64
“属性”Name String
NCNameNCName String
negativeIntegernegativeInteger String
NMTOKENNMTOKEN String
NMTOKENSNMTOKENS String
normalizedStringnormalizedString String
nonNegativeIntegernonNegativeInteger String
nonPositiveIntegernonPositiveInteger String
NOTATIONNOTATION String
positiveIntegerpositiveInteger String
QNameQName XmlQualifiedName
durationduration String
字符串string String
shortshort Int16
timetime DateTime
令牌token String
unsignedByteunsignedByte Byte
unsignedIntunsignedInt UInt32
unsignedLongunsignedLong UInt64
unsignedShortunsignedShort UInt16

适用于