XmlAttributeAttribute.DataType プロパティ
XmlSerializer によって生成された XML 属性の XSD データ型を取得または設定します。
Public Property DataType As String
[C#]
public string DataType {get; set;}
[C++]
public: __property String* get_DataType();public: __property void set_DataType(String*);
[JScript]
public function get DataType() : String;public function set DataType(String);
プロパティ値
W3C (World Wide Web Consortium) (www.w3.org) のドキュメント『XML Schema: DataTypes』で定義されている XSD (XML スキーマ ドキュメント) データ型。
解説
XSD 単純データ型と、それに相当する .NET データ型の表を次に示します。
XSD base64Binary データ型と XSD hexBinary データ型の場合は、 Byte 構造体の配列を使用し、 DataType プロパティがデータ型に応じて "base64Binary" または "hexBinary" に設定されている XmlArrayItemAttribute を適用します。XSD time データ型と XSD date データ型の場合は、 DateTime 型を使用し、 DataType が "date" または "time" に設定されている XmlAttributeAttribute を適用します。
文字列に割り当てられたすべての XSD 型について、 DataType プロパティが XSD 型に設定されている XmlAttributeAttribute を適用します。ただし、これによってシリアル化形式が変更されることはなく、メンバのスキーマだけが変更されます。
メモ プロパティは、大文字小文字を区別します。このため、各 XSD データ型を正確に設定する必要があります。
メモ バイナリ データを XML 要素として渡すほうが、バイナリ データを XML 属性として渡すよりも効率的です。
XML データ型の詳細については、W3C (World Wide Web Consortium) (www.w3.org) のドキュメント『XML Schema Part 2: Datatypes』を参照してください。
XSD データ型 | .NET データ型 |
---|---|
anyURI | String |
base64Binary | Byte オブジェクトの配列 |
boolean | Boolean |
byte | SByte |
date | DateTime |
dateTime | DateTime |
decimal | Decimal |
double | Double |
ENTITY | String |
ENTITIES | String |
float | Single |
gDay | String |
gMonth | String |
gMonthDay | String |
gYear | String |
gYearMonth | String |
hexBinary | Byte オブジェクトの配列 |
ID | String |
IDREF | String |
IDREFS | String |
int | Int32 |
integer | String |
language | String |
long | Int64 |
Name | String |
NCName | String |
negativeInteger | String |
NMTOKEN | String |
NMTOKENS | String |
normalizedString | String |
nonNegativeInteger | String |
nonPositiveInteger | String |
NOTATION | String |
positiveInteger | String |
QName | XmlQualifiedName |
duration | String |
string | String |
short | Int16 |
time | DateTime |
token | String |
unsignedByte | Byte |
unsignedInt | UInt32 |
unsignedLong | UInt64 |
unsignedShort | UInt16 |
使用例
[Visual Basic, C#, C++] XmlAttributeAttribute を 2 つのメンバに適用し、 DataType プロパティ セットに異なる値を設定する例を次に示します。
public class Group
<XmlAttribute(DataType := "string")> _
public Name As string
<XmlAttribute (DataType := "base64Binary")> _
public Hex64Code () As byte
End Class
[C#]
public class Group{
[XmlAttribute(DataType = "string")]
public string Name;
[XmlAttribute (DataType = "base64Binary")]
public byte[] Hex64Code;
}
[C++]
public __gc class Group{
public:
[XmlAttributeAttribute(DataType = S"string")]
String* Name;
public:
[XmlAttributeAttribute (DataType = S"base64Binary")]
Byte Hex64Code[];
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
XmlAttributeAttribute クラス | XmlAttributeAttribute メンバ | System.Xml.Serialization 名前空間