XmlAttributeAttribute クラスとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlAttributeAttribute クラスの意味・解説 

XmlAttributeAttribute クラス

XmlSerializer がクラス メンバXML 属性としてシリアル化する必要があることを指定します

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

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field
 Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue)>
 _
Public Class XmlAttributeAttribute
    Inherits Attribute
Dim instance As XmlAttributeAttribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)]
 
public class XmlAttributeAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Parameter|AttributeTargets::ReturnValue)]
 
public ref class XmlAttributeAttribute : public
 Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)
 */ 
public class XmlAttributeAttribute extends
 Attribute
AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)
 
public class XmlAttributeAttribute extends
 Attribute
解説解説

XmlAttributeAttribute は、XmlSerializerオブジェクトシリアル化または逆シリアル化する方法制御する一連の属性属します類似する属性の完全な一覧については、「XML シリアル化制御する属性」を参照してください

XmlAttributeAttribute は、パブリック フィールドまたはパブリック プロパティ適用され場合、それらのフィールドプロパティXML 属性としてシリアル化するように XmlSerializer通知します既定では、XmlSerializer は、パブリック フィールドまたはパブリック プロパティXML 要素としてシリアル化ます。

XmlAttributeAttribute は、XML スキーマ定義言語 (XSD) の単純型 (anySimpleType 型から派生した組み込みデータ型を含む) の 1 つ割り当てることができる値または値の配列返すパブリック フィールドまたはパブリック プロパティにだけ割り当てることができますGuidChar列挙体など、XSD 単純型に割り当てることができるすべてのデータ型使用できますXSD 型のリスト、および .NET データ型への割り当て方法については、DataType プロパティトピック参照してください

XmlAttributeAttribute と共に設定できる特殊な属性2 つありますxml:lang (言語指定) 属性および xml:space (空白処理方法指定) 属性です。これらの属性は、XML処理するアプリケーションだけに関連がある情報伝達するための属性です。これらを設定するコードの例次に示します

[XmlAttribute("xml:lang")]
 public string Lang;
 // Set this to 'default' or 'preserve'.
 [XmlAttribute("space", 
 Namespace = "http://www.w3.org/XML/1998/namespace")]
 public string Space 
 [Visual Basic]
 <XmlAttribute("xml:lang")> _
 Public Lang As String 
 ' Set this to 'default' or 'preserve'.
 <XmlAttribute("space", _
 Namespace:= "http://www.w3.org/XML/1998/namespace")> _
 Public Space As String

属性使用方法については、「属性使用したメタデータ拡張」を参照してください

メモメモ

コードでは、XmlAttributeAttribute代わりに XmlAttribute という短い語使用できます

使用例使用例

XmlAttributeAttribute適用対象となる複数フィールド保持しているクラスシリアル化する例を次に示します

Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Xml.Schema


Public Class Group
    <XmlAttribute(Namespace := "http://www.cpandl.com")>
 _
        Public GroupName As String
    
    <XmlAttribute(DataType := "base64Binary")>
 _
        Public GroupNumber() As Byte
    
    <XmlAttribute(DataType := "date", AttributeName
 := "CreationDate")> _
        Public Today As DateTime
End Class

Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        test.SerializeObject("Attributes.xml")
    End Sub 
    
    Public Sub SerializeObject(ByVal
 filename As String)
        ' Create an instance of the XmlSerializer class.
        Dim mySerializer As New
 XmlSerializer(GetType(Group))
        
        ' Writing the file requires a TextWriter.
        Dim writer As New
 StreamWriter(filename)
        
        ' Create an instance of the class that will be serialized.
        Dim myGroup As New
 Group()
        
        ' Set the object properties.
        myGroup.GroupName = ".NET"
        
        Dim hexByte() As Byte
 = {Convert.ToByte(100), Convert.ToByte(50)}
        myGroup.GroupNumber = hexByte
        
        Dim myDate As New
 DateTime(2001, 1, 10)
        myGroup.Today = myDate
        
        ' Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myGroup)
        writer.Close()
    End Sub
End Class

using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

public class Group
{
   [XmlAttribute (Namespace = "http://www.cpandl.com")]
   public string GroupName;
   
   [XmlAttribute(DataType = "base64Binary")]
   public Byte [] GroupNumber;

   [XmlAttribute(DataType = "date", AttributeName = "CreationDate")]
   public DateTime Today;
}


 
public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("Attributes.xml");
   }


   public void SerializeObject(string
 filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  
      new XmlSerializer(typeof(Group));

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      myGroup.GroupName = ".NET";

      Byte [] hexByte = new Byte[2]{Convert.ToByte(100),
      Convert.ToByte(50)};
      myGroup.GroupNumber = hexByte;

      DateTime myDate = new DateTime(2001,1,10);
      myGroup.Today = myDate;

      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
       writer.Close();
   }
}
   
#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;
using namespace System::Xml::Schema;

public ref class Group
{
public:

   [XmlAttributeAttribute(Namespace="http://www.cpandl.com")]
   String^ GroupName;

   [XmlAttributeAttribute(DataType="base64Binary")]
   array<Byte>^GroupNumber;

   [XmlAttributeAttribute(DataType="date",AttributeName="CreationDate")]
   DateTime Today;
};

void SerializeObject( String^ filename )
{
   // Create an instance of the XmlSerializer class.
   XmlSerializer^ mySerializer = gcnew XmlSerializer( Group::typeid );

   // Writing the file requires a TextWriter.
   TextWriter^ writer = gcnew StreamWriter( filename );

   // Create an instance of the class that will be serialized.
   Group^ myGroup = gcnew Group;

   // Set the object properties.
   myGroup->GroupName = ".NET";
   array<Byte>^hexByte = {Convert::ToByte( 100 ),Convert::ToByte( 50 )};
   myGroup->GroupNumber = hexByte;
   DateTime myDate = DateTime(2001,1,10);
   myGroup->Today = myDate;

   // Serialize the class, and close the TextWriter.
   mySerializer->Serialize( writer, myGroup );
   writer->Close();
}

int main()
{
   SerializeObject( "Attributes.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;
import System.Xml.Schema.*;

public class Group
{
    /** @attribute XmlAttribute(Namespace = "http://www.cpandl.com")
     */
    public String groupName;

    /** @attribute XmlAttribute(DataType = "base64Binary")
     */
    public System.Byte groupNumber[];

    /** @attribute XmlAttribute(DataType = "date", AttributeName = "CreationDate")
     */
    public DateTime today;
} //Group

public class Run
{
    public static void main(String[]
 args)
    {
        Run test = new Run();
        test.SerializeObject("Attributes.xml");
    } //main

    public void SerializeObject(String fileName)
    {
        // Create an instance of the XmlSerializer class.
        XmlSerializer mySerializer = new XmlSerializer(Group.class.ToType());
        
        // Writing the file requires a TextWriter.
        TextWriter writer = new StreamWriter(fileName);

        // Create an instance of the class that will be serialized.
        Group myGroup = new Group();

        // Set the object properties.
        myGroup.groupName = ".NET";

        System.Byte hexByte[] =
            new System.Byte[] { (System.Byte)Convert.ToSByte(100)
,
            (System.Byte)Convert.ToSByte(50)};
        myGroup.groupNumber = hexByte;

        DateTime myDate = new DateTime(2001, 1, 10);
        myGroup.today = myDate;

        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myGroup);
        writer.Close();
    } //SerializeObject
} //Run
継承階層継承階層
System.Object
   System.Attribute
    System.Xml.Serialization.XmlAttributeAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAttributeAttribute メンバ
System.Xml.Serialization 名前空間



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

辞書ショートカット

すべての辞書の索引

「XmlAttributeAttribute クラス」の関連用語

XmlAttributeAttribute クラスのお隣キーワード
検索ランキング

   

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



XmlAttributeAttribute クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS