XmlAttributeAttribute.DataType 屬性

定義

取得或設定由 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, set
Public Property DataType As String

屬性值

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 base64BinaryhexBinary 資料類型,請使用結構的陣列 Byte ,並視需要將 屬性設定為 「base64Binary」 或 「hexBinary」 套用 XmlArrayItemAttribute DataType 。 針對 XSD timedate 資料類型,請使用 DateTime 型別並套用 XmlAttributeAttribute ,並將 DataType 設定為 「date」 或 「time」。

針對對應至字串的每個 XSD 類型,請套用 其 XmlAttributeAttribute DataType 屬性設定為 XSD 型別的 。 不過,這不會變更序列化格式,只會變更成員的架構。

注意

屬性會區分大小寫,因此您必須將其設定為其中一個 XSD 資料類型。

注意

將二進位資料當做 XML 元素傳遞比傳遞為 XML 屬性更有效率。

如需 XML 資料類型的詳細資訊,請參閱來自萬維網聯盟的 XML 架構第 2 部分:DataTypes 檔。

XSD 資料類型 .NET 資料類型
anyURI String
base64Binary Byte物件的陣列
boolean Boolean
byte 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
token String
unsignedByte Byte
unsignedInt UInt32
unsignedLong UInt64
unsignedShort UInt16

適用於