XmlElementAttribute.DataType プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlElementAttribute.DataType プロパティの意味・解説 

XmlElementAttribute.DataType プロパティ

XmlSerializer によって生成されXML 要素XML スキーマ定義 (XSD: XML Schema Definition) データ型取得または設定します

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

例外例外
解説解説

XML スキーマの単純データ型と、それに相当する .NET データ型の表を次に示します

XML スキーマbase64Binary データ型hexBinary データ型については、Byte 構造体配列使用しDataTypeそれぞれ "base64Binary" または "hexBinary" に設定した XmlElementAttribute を適用します。XML スキーマtime データ型および date データ型については、DateTime 型を使用してDataType が "date" または "time" に設定されている XmlElementAttribute適用します。

文字列割り当てられすべての XML スキーマ型について、DataType プロパティXML スキーマ型に設定されている XmlElementAttribute適用します。これにより、メンバスキーマだけでなくシリアル化形式変更できる可能性あります

メモメモ

このプロパティでは大文字と小文字区別されるため、XML スキーマ データ型正しく設定する必要があります

メモメモ

バイナリ データは、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

使用例使用例

ExtraInfo という名前のフィールドがある Group という名前のクラスシリアル化し、ArrayList を返す例を次に示します。この例は、XmlElementAttribute2 つインスタンスフィールド適用しそれぞれのインスタンスに対して異な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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlElementAttribute クラス
XmlElementAttribute メンバ
System.Xml.Serialization 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlElementAttribute.DataType プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlElementAttribute.DataType プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlElementAttribute.DataType プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XmlElementAttribute.DataType プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlElementAttribute.DataType プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS