XmlElementAttribute.DataType プロパティ
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlElementAttribute Dim value As String value = instance.DataType instance.DataType = value
/** @property */ public String get_DataType () /** @property */ public void set_DataType (String value)
W3C (World Wide Web Consortium) (www.w3.org ) のドキュメント『XML Schema Part 2: Datatypes』で定義されている XML スキーマ データ型。


XML スキーマの単純データ型と、それに相当する .NET データ型の表を次に示します。
XML スキーマの base64Binary データ型と hexBinary データ型については、Byte 構造体の配列を使用し、DataType をそれぞれ "base64Binary" または "hexBinary" に設定した XmlElementAttribute を適用します。XML スキーマの time データ型および date データ型については、DateTime 型を使用して、DataType が "date" または "time" に設定されている XmlElementAttribute を適用します。
文字列に割り当てられたすべての XML スキーマ型について、DataType プロパティが XML スキーマ型に設定されている XmlElementAttribute を適用します。これにより、メンバのスキーマだけでなくシリアル化形式も変更できる可能性があります。
![]() |
---|
XML データ型の詳細については、W3C (World Wide Web Consortium) (www.w3.org) のドキュメント『XML Schema Part 2: Datatypes』を参照してください。
anyURI | |
base64Binary | |
SByte | |
gDay | |
gMonth | |
gMonthDay | |
gYear | |
gYearMonth | |
hexBinary | |
IDREF | |
IDREFS | |
Int32 | |
Int64 | |
NCName | |
negativeInteger | |
NMTOKEN | |
NMTOKENS | |
normalizedString | |
nonNegativeInteger | |
nonPositiveInteger | |
positiveInteger | |
QName | XmlQualifiedName |
Int16 | |
unsignedByte | |
unsignedInt | UInt32 |
unsignedLong | UInt64 |
unsignedShort | UInt16 |

ExtraInfo という名前のフィールドがある Group という名前のクラスをシリアル化し、ArrayList を返す例を次に示します。この例は、XmlElementAttribute の 2 つのインスタンスをフィールドに適用し、それぞれのインスタンスに対して異なる DataType 値を指定します。各インスタンスは、配列に挿入されている指定した型を XmlSerializer でシリアル化できるようにします。
Imports System Imports System.Collections Imports System.IO Imports System.Xml.Serialization Public Class Group ' Apply two XmlElementAttributes to the field. Set the DataType ' to string and int to allow the ArrayList to accept ' both types. The Namespace is also set to different values ' for each type. <XmlElement(DataType := "string", _ Type := GetType(String), _ Namespace := "http://www.cpandl.com"), _ XmlElement(DataType := "int", _ Type := GetType(Integer), _ Namespace := "http://www.cohowinery.com")> _ Public ExtraInfo As ArrayList End Class Public Class Run Public Shared Sub Main() Dim test As New Run() test.SerializeObject("ElementTypes.xml") End Sub Public Sub SerializeObject(filename As String) ' A TextWriter is needed to write the file. Dim writer As New StreamWriter(filename) ' Create the XmlSerializer using the XmlAttributeOverrides. Dim s As New XmlSerializer(GetType(Group)) ' Create the object to serialize. Dim myGroup As New Group() ' Add a string and an integer to the ArrayList returned ' by the ExtraInfo field. myGroup.ExtraInfo = New ArrayList() myGroup.ExtraInfo.Add("hello") myGroup.ExtraInfo.Add(100) ' Serialize the object and close the TextWriter. s.Serialize(writer, myGroup) writer.Close() End Sub End Class
using System; using System.Collections; using System.IO; using System.Xml.Serialization; public class Group { /* Apply two XmlElementAttributes to the field. Set the DataType to string an int to allow the ArrayList to accept both types. The Namespace is also set to different values for each type. */ [XmlElement(DataType = "string", Type = typeof(string), Namespace = "http://www.cpandl.com"), XmlElement(DataType = "int", Namespace = "http://www.cohowinery.com", Type = typeof(int))] public ArrayList ExtraInfo; } public class Run { public static void Main() { Run test = new Run(); test.SerializeObject("ElementTypes.xml"); } public void SerializeObject(string filename) { // A TextWriter is needed to write the file. TextWriter writer = new StreamWriter(filename); // Create the XmlSerializer using the XmlAttributeOverrides. XmlSerializer s = new XmlSerializer(typeof(Group)); // Create the object to serialize. Group myGroup = new Group(); /* Add a string and an integer to the ArrayList returned by the ExtraInfo field. */ myGroup.ExtraInfo = new ArrayList(); myGroup.ExtraInfo.Add("hello"); myGroup.ExtraInfo.Add(100); // Serialize the object and close the TextWriter. s.Serialize(writer,myGroup); writer.Close(); } }
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::Collections; using namespace System::IO; using namespace System::Xml::Serialization; public ref class Group { public: /* Apply two XmlElementAttributes to the field. Set the DataType to string an int to allow the ArrayList to accept both types. The Namespace is also set to different values for each type. */ [XmlElement(DataType="string", Type=String::typeid, Namespace="http://www.cpandl.com"), XmlElement(DataType="snippet1>", Namespace="http://www.cohowinery.com", Type=Int32::typeid)] ArrayList^ ExtraInfo; }; void SerializeObject( String^ filename ) { // A TextWriter is needed to write the file. TextWriter^ writer = gcnew StreamWriter( filename ); // Create the XmlSerializer using the XmlAttributeOverrides. XmlSerializer^ s = gcnew XmlSerializer( Group::typeid ); // Create the object to serialize. Group^ myGroup = gcnew Group; /* Add a string and an integer to the ArrayList returned by the ExtraInfo field. */ myGroup->ExtraInfo = gcnew ArrayList; myGroup->ExtraInfo->Add( "hello" ); myGroup->ExtraInfo->Add( 100 ); // Serialize the object and close the TextWriter. s->Serialize( writer, myGroup ); writer->Close(); } int main() { SerializeObject( "ElementTypes.xml" ); }
import System.*; import System.Collections.*; import System.IO.*; import System.Xml.Serialization.*; public class Group { /* Apply two XmlElementAttributes to the field. Set the DataType to string an int to allow the ArrayList to accept both types. The Namespace is also set to different values for each type. */ /** @attribute XmlElement(DataType = "string", Type = String.class, Namespace = "http://www.cpandl.com") @attribute XmlElement(DataType = "int", Namespace = "http://www.cohowinery.com", Type = int.class) */ public ArrayList extraInfo; } //Group public class Run { public static void main(String[] args) { Run test = new Run(); test.SerializeObject("ElementTypes.xml"); } //main public void SerializeObject(String fileName) { // A TextWriter is needed to write the file. TextWriter writer = new StreamWriter(fileName); // Create the XmlSerializer using the XmlAttributeOverrides. XmlSerializer s = new XmlSerializer(Group.class.ToType()); // Create the object to serialize. Group myGroup = new Group(); /* Add a string and an integer to the ArrayList returned by the extraInfo field. */ myGroup.extraInfo = new ArrayList(); myGroup.extraInfo.Add("hello"); myGroup.extraInfo.Add((Int32)100); // Serialize the object and close the TextWriter. s.Serialize(writer, myGroup); writer.Close(); } //SerializeObject } //Run

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXmlElementAttribute.DataType プロパティを検索する場合は、下記のリンクをクリックしてください。

- XmlElementAttribute.DataType プロパティのページへのリンク