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 名前空間

XmlAttributeAttribute コンストラクタ ()

XmlAttributeAttribute クラス新しインスタンス初期化します。

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

Dim instance As New XmlAttributeAttribute
public XmlAttributeAttribute ()
public:
XmlAttributeAttribute ()
public XmlAttributeAttribute ()
public function XmlAttributeAttribute ()
使用例使用例
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

' This is the class that will be serialized.
Public Class Student
   Public StudentName As String
   Public StudentNumber As Integer
End Class

Public Class Book
   Public BookName As String
   Public BookNumber As Integer
End Class

Public Class XMLAttributeAttribute_ctr1

   Public Shared Sub Main()
      Dim myAttribute As New
 XMLAttributeAttribute_ctr1()
      myAttribute.SerializeObject("Student.xml", "Book.xml")
   End Sub

   Public Sub SerializeObject(studentFilename
 As String, bookFilename As
 String)
      Dim mySerializer As XmlSerializer
      Dim writer As TextWriter

      ' Create the XmlAttributeOverrides and XmlAttributes objects.
      Dim myXmlAttributeOverrides As New
 XmlAttributeOverrides()
      Dim myXmlAttributes As New
 XmlAttributes()

      ' Create an XmlAttributeAttribute set it to the XmlAttribute property
 of the XmlAttributes object.
      Dim myXmlAttributeAttribute As New
 XmlAttributeAttribute()
      myXmlAttributeAttribute.AttributeName = "Name"
      myXmlAttributes.XmlAttribute = myXmlAttributeAttribute

      ' Add to the XmlAttributeOverrides. Specify the member name.
      myXmlAttributeOverrides.Add(GetType(Student), "StudentName",
 myXmlAttributes)

      ' Create the XmlSerializer.
      mySerializer = New XmlSerializer(GetType(Student),
 myXmlAttributeOverrides)

      writer = New StreamWriter(studentFilename)

      ' Create an instance of the class that will be serialized.
      Dim myStudent As New
 Student()

      ' Set the Name property, which will be generated as an XML attribute.
 
      myStudent.StudentName = "James"
      myStudent.StudentNumber = 1
      ' Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myStudent)
      writer.Close()

      ' Create the XmlAttributeOverrides and XmlAttributes objects.
      Dim myXmlBookAttributeOverrides As New
 XmlAttributeOverrides()
      Dim myXmlBookAttributes As New
 XmlAttributes()

      ' Create an XmlAttributeAttribute set it to the XmlAttribute property
 of the XmlAttributes object.
      Dim myXmlBookAttributeAttribute As New
 XmlAttributeAttribute("Name")
      myXmlBookAttributes.XmlAttribute = myXmlBookAttributeAttribute

      ' Add to the XmlAttributeOverrides. Specify the member name.
      myXmlBookAttributeOverrides.Add(GetType(Book), "BookName",
 myXmlBookAttributes)

      ' Create the XmlSerializer.
      mySerializer = New XmlSerializer(GetType(Book),
 myXmlBookAttributeOverrides)

      writer = New StreamWriter(bookFilename)

      ' Create an instance of the class that will be serialized.
      Dim myBook As New
 Book()

      ' Set the Name property, which will be generated as an XML attribute.
      myBook.BookName = ".NET"
      myBook.BookNumber = 10
      ' Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myBook)
      writer.Close()
   End Sub
End Class
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Student
{
   public string StudentName;
   public int StudentNumber;
}
 
public class Book
{
   public string BookName;
   public int BookNumber;
}
public class XMLAttributeAttribute_ctr1
{
   public static void Main()
   {
      XMLAttributeAttribute_ctr1 myAttribute = 
                                 new XMLAttributeAttribute_ctr1();
      myAttribute.SerializeObject("Student.xml","Book.xml");
   }
 
   public void SerializeObject(string
 studentFilename,string bookFilename)
   {
      XmlSerializer mySerializer;
      TextWriter writer;

      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides myXmlAttributeOverrides = 
                                                     new XmlAttributeOverrides();
      XmlAttributes myXmlAttributes = new XmlAttributes();

      /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
      XmlAttributeAttribute myXmlAttributeAttribute = 
                                                new XmlAttributeAttribute();
      myXmlAttributeAttribute.AttributeName="Name";
      myXmlAttributes.XmlAttribute = myXmlAttributeAttribute;
      
      
      // Add to the XmlAttributeOverrides. Specify the member name.
      myXmlAttributeOverrides.Add(typeof(Student), "StudentName", 
                                                      myXmlAttributes);

      // Create the XmlSerializer.
      mySerializer = new  XmlSerializer(typeof(Student), 
                                                myXmlAttributeOverrides);
      
      writer = new StreamWriter(studentFilename);

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

      // Set the Name property, which will be generated as an XML attribute.
 
      myStudent.StudentName= "James";
      myStudent.StudentNumber=1;
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myStudent);
      writer.Close();

      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides myXmlBookAttributeOverrides = 
                                                new XmlAttributeOverrides();
      XmlAttributes myXmlBookAttributes = new XmlAttributes();

      /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
      XmlAttributeAttribute myXmlBookAttributeAttribute = 
                                           new XmlAttributeAttribute("Name");
      myXmlBookAttributes.XmlAttribute = myXmlBookAttributeAttribute;
      
      
      // Add to the XmlAttributeOverrides. Specify the member name.
      myXmlBookAttributeOverrides.Add(typeof(Book), "BookName", 
                                             myXmlBookAttributes);

      // Create the XmlSerializer.
      mySerializer = new  XmlSerializer(typeof(Book), 
                                       myXmlBookAttributeOverrides);
      
      writer = new StreamWriter(bookFilename);

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

      // Set the Name property, which will be generated as an XML attribute.
 
      myBook.BookName= ".NET";
      myBook.BookNumber=10;
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myBook);
      writer.Close();

   }
}
#using <System.dll>
#using <System.xml.dll>

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

// This is the class that will be serialized.
public ref class Student
{
public:
   String^ StudentName;
   int StudentNumber;
};

public ref class Book
{
public:
   String^ BookName;
   int BookNumber;
};

void SerializeObject( String^ studentFilename, String^ bookFilename
 )
{
   XmlSerializer^ mySerializer;
   TextWriter^ writer;

   // Create the XmlAttributeOverrides and XmlAttributes objects.
   XmlAttributeOverrides^ myXmlAttributeOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ myXmlAttributes = gcnew XmlAttributes;

   /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
   XmlAttributeAttribute^ myXmlAttributeAttribute = gcnew XmlAttributeAttribute;
   myXmlAttributeAttribute->AttributeName = "Name";
   myXmlAttributes->XmlAttribute = myXmlAttributeAttribute;

   // Add to the XmlAttributeOverrides. Specify the member name.
   myXmlAttributeOverrides->Add( Student::typeid, "StudentName", myXmlAttributes
 );

   // Create the XmlSerializer.
   mySerializer = gcnew XmlSerializer( Student::typeid,myXmlAttributeOverrides );
   writer = gcnew StreamWriter( studentFilename );

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

   // Set the Name property, which will be generated as an XML attribute.
 
   myStudent->StudentName = "James";
   myStudent->StudentNumber = 1;

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

   // Create the XmlAttributeOverrides and XmlAttributes objects.
   XmlAttributeOverrides^ myXmlBookAttributeOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ myXmlBookAttributes = gcnew XmlAttributes;

   /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
   XmlAttributeAttribute^ myXmlBookAttributeAttribute = gcnew XmlAttributeAttribute(
 "Name" );
   myXmlBookAttributes->XmlAttribute = myXmlBookAttributeAttribute;

   // Add to the XmlAttributeOverrides. Specify the member name.
   myXmlBookAttributeOverrides->Add( Book::typeid, "BookName", myXmlBookAttributes
 );

   // Create the XmlSerializer.
   mySerializer = gcnew XmlSerializer( Book::typeid,myXmlBookAttributeOverrides );
   writer = gcnew StreamWriter( bookFilename );

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

   // Set the Name property, which will be generated as an XML attribute.
 
   myBook->BookName = ".NET";
   myBook->BookNumber = 10;

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

int main()
{
   SerializeObject(  "Student.xml",  "Book.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;

// This is the class that will be serialized.
public class Student
{
    public String studentName;
    public int studentNumber;
} //Student

public class Book
{
    public String bookName;
    public int bookNumber;
} //Book

public class XmlAttributeAttribute_Ctr1
{
    public static void main(String[]
 args)
    {
        XmlAttributeAttribute_Ctr1 myAttribute =
            new XmlAttributeAttribute_Ctr1();
        myAttribute.SerializeObject("Student.xml", "Book.xml");
    } //main

    public void SerializeObject(String studentfileName,
 String bookfileName)
    {
        XmlSerializer mySerializer;
        TextWriter writer;
        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides myXmlAttributeOverrides =
            new XmlAttributeOverrides();
        XmlAttributes myXmlAttributes = new XmlAttributes();

        /* Create an XmlAttributeAttribute set it to 
           the XmlAttribute property of the XmlAttributes object.
         */
        XmlAttributeAttribute myXmlAttributeAttribute = 
            new XmlAttributeAttribute();
        myXmlAttributeAttribute.set_AttributeName("Name");
        myXmlAttributes.set_XmlAttribute(myXmlAttributeAttribute);
        // Add to the XmlAttributeOverrides. Specify the member name.
        myXmlAttributeOverrides.Add(Student.class.ToType(), "studentName"
,
            myXmlAttributes);
        // Create the XmlSerializer.
        mySerializer = new XmlSerializer(Student.class.ToType()
,
            myXmlAttributeOverrides);

        writer = new StreamWriter(studentfileName);
        // Create an instance of the class that will be serialized.
        Student myStudent = new Student();
        // Set the Name property, which will be generated as an XML attribute.
 
        myStudent.studentName = "James";
        myStudent.studentNumber = 1;
        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myStudent);
        writer.Close();
        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides myXmlBookAttributeOverrides = 
            new XmlAttributeOverrides();
        XmlAttributes myXmlBookAttributes = new XmlAttributes();

        /* Create an XmlAttributeAttribute set it to 
           the XmlAttribute property of the XmlAttributes object.
         */
        XmlAttributeAttribute myXmlBookAttributeAttribute = 
            new XmlAttributeAttribute("Name");
        myXmlBookAttributes.set_XmlAttribute(myXmlBookAttributeAttribute);
        // Add to the XmlAttributeOverrides. Specify the member name.
        myXmlBookAttributeOverrides.Add(Book.class.ToType(), "BookName",
 
            myXmlBookAttributes);
        // Create the XmlSerializer.
        mySerializer = new XmlSerializer(Book.class.ToType()
,
            myXmlBookAttributeOverrides);

        writer = new StreamWriter(bookfileName);
        // Create an instance of the class that will be serialized.
        Book myBook = new Book();
        // Set the Name property, which will be generated as an XML attribute.
 
        myBook.bookName = ".NET";
        myBook.bookNumber = 10;
        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myBook);
        writer.Close();
    } //SerializeObject 
} //XmlAttributeAttribute_Ctr1
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAttributeAttribute クラス
XmlAttributeAttribute メンバ
System.Xml.Serialization 名前空間

XmlAttributeAttribute コンストラクタ (String, Type)

XmlAttributeAttribute クラス新しインスタンス初期化します。

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

Public Sub New ( _
    attributeName As String, _
    type As Type _
)
Dim attributeName As String
Dim type As Type

Dim instance As New XmlAttributeAttribute(attributeName,
 type)
public XmlAttributeAttribute (
    string attributeName,
    Type type
)
public:
XmlAttributeAttribute (
    String^ attributeName, 
    Type^ type
)
public XmlAttributeAttribute (
    String attributeName, 
    Type type
)
public function XmlAttributeAttribute (
    attributeName : String, 
    type : Type
)

パラメータ

attributeName

生成される XML 属性の名前。

type

属性取得するために使用する Type

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAttributeAttribute クラス
XmlAttributeAttribute メンバ
System.Xml.Serialization 名前空間

XmlAttributeAttribute コンストラクタ (Type)


XmlAttributeAttribute コンストラクタ (String)

XmlAttributeAttribute クラス新しインスタンス初期化し生成されXML 属性の名前を指定します

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

Public Sub New ( _
    attributeName As String _
)
Dim attributeName As String

Dim instance As New XmlAttributeAttribute(attributeName)
public XmlAttributeAttribute (
    string attributeName
)
public:
XmlAttributeAttribute (
    String^ attributeName
)
public XmlAttributeAttribute (
    String attributeName
)
public function XmlAttributeAttribute (
    attributeName : String
)

パラメータ

attributeName

XmlSerializer が生成する XML 属性の名前。

使用例使用例
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

' This is the class that will be serialized.
Public Class Student
   Public StudentName As String
   Public StudentNumber As Integer
End Class

Public Class Book
   Public BookName As String
   Public BookNumber As Integer
End Class

Public Class XMLAttributeAttribute_ctr1

   Public Shared Sub Main()
      Dim myAttribute As New
 XMLAttributeAttribute_ctr1()
      myAttribute.SerializeObject("Student.xml", "Book.xml")
   End Sub

   Public Sub SerializeObject(studentFilename
 As String, bookFilename As
 String)
      Dim mySerializer As XmlSerializer
      Dim writer As TextWriter

      ' Create the XmlAttributeOverrides and XmlAttributes objects.
      Dim myXmlAttributeOverrides As New
 XmlAttributeOverrides()
      Dim myXmlAttributes As New
 XmlAttributes()

      ' Create an XmlAttributeAttribute set it to the XmlAttribute property
 of the XmlAttributes object.
      Dim myXmlAttributeAttribute As New
 XmlAttributeAttribute()
      myXmlAttributeAttribute.AttributeName = "Name"
      myXmlAttributes.XmlAttribute = myXmlAttributeAttribute

      ' Add to the XmlAttributeOverrides. Specify the member name.
      myXmlAttributeOverrides.Add(GetType(Student), "StudentName",
 myXmlAttributes)

      ' Create the XmlSerializer.
      mySerializer = New XmlSerializer(GetType(Student),
 myXmlAttributeOverrides)

      writer = New StreamWriter(studentFilename)

      ' Create an instance of the class that will be serialized.
      Dim myStudent As New
 Student()

      ' Set the Name property, which will be generated as an XML attribute.
 
      myStudent.StudentName = "James"
      myStudent.StudentNumber = 1
      ' Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myStudent)
      writer.Close()

      ' Create the XmlAttributeOverrides and XmlAttributes objects.
      Dim myXmlBookAttributeOverrides As New
 XmlAttributeOverrides()
      Dim myXmlBookAttributes As New
 XmlAttributes()

      ' Create an XmlAttributeAttribute set it to the XmlAttribute property
 of the XmlAttributes object.
      Dim myXmlBookAttributeAttribute As New
 XmlAttributeAttribute("Name")
      myXmlBookAttributes.XmlAttribute = myXmlBookAttributeAttribute

      ' Add to the XmlAttributeOverrides. Specify the member name.
      myXmlBookAttributeOverrides.Add(GetType(Book), "BookName",
 myXmlBookAttributes)

      ' Create the XmlSerializer.
      mySerializer = New XmlSerializer(GetType(Book),
 myXmlBookAttributeOverrides)

      writer = New StreamWriter(bookFilename)

      ' Create an instance of the class that will be serialized.
      Dim myBook As New
 Book()

      ' Set the Name property, which will be generated as an XML attribute.
      myBook.BookName = ".NET"
      myBook.BookNumber = 10
      ' Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myBook)
      writer.Close()
   End Sub
End Class
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Student
{
   public string StudentName;
   public int StudentNumber;
}
 
public class Book
{
   public string BookName;
   public int BookNumber;
}
public class XMLAttributeAttribute_ctr1
{
   public static void Main()
   {
      XMLAttributeAttribute_ctr1 myAttribute = 
                                 new XMLAttributeAttribute_ctr1();
      myAttribute.SerializeObject("Student.xml","Book.xml");
   }
 
   public void SerializeObject(string
 studentFilename,string bookFilename)
   {
      XmlSerializer mySerializer;
      TextWriter writer;

      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides myXmlAttributeOverrides = 
                                                     new XmlAttributeOverrides();
      XmlAttributes myXmlAttributes = new XmlAttributes();

      /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
      XmlAttributeAttribute myXmlAttributeAttribute = 
                                                new XmlAttributeAttribute();
      myXmlAttributeAttribute.AttributeName="Name";
      myXmlAttributes.XmlAttribute = myXmlAttributeAttribute;
      
      
      // Add to the XmlAttributeOverrides. Specify the member name.
      myXmlAttributeOverrides.Add(typeof(Student), "StudentName", 
                                                      myXmlAttributes);

      // Create the XmlSerializer.
      mySerializer = new  XmlSerializer(typeof(Student), 
                                                myXmlAttributeOverrides);
      
      writer = new StreamWriter(studentFilename);

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

      // Set the Name property, which will be generated as an XML attribute.
 
      myStudent.StudentName= "James";
      myStudent.StudentNumber=1;
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myStudent);
      writer.Close();

      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides myXmlBookAttributeOverrides = 
                                                new XmlAttributeOverrides();
      XmlAttributes myXmlBookAttributes = new XmlAttributes();

      /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
      XmlAttributeAttribute myXmlBookAttributeAttribute = 
                                           new XmlAttributeAttribute("Name");
      myXmlBookAttributes.XmlAttribute = myXmlBookAttributeAttribute;
      
      
      // Add to the XmlAttributeOverrides. Specify the member name.
      myXmlBookAttributeOverrides.Add(typeof(Book), "BookName", 
                                             myXmlBookAttributes);

      // Create the XmlSerializer.
      mySerializer = new  XmlSerializer(typeof(Book), 
                                       myXmlBookAttributeOverrides);
      
      writer = new StreamWriter(bookFilename);

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

      // Set the Name property, which will be generated as an XML attribute.
 
      myBook.BookName= ".NET";
      myBook.BookNumber=10;
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myBook);
      writer.Close();

   }
}
#using <System.dll>
#using <System.xml.dll>

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

// This is the class that will be serialized.
public ref class Student
{
public:
   String^ StudentName;
   int StudentNumber;
};

public ref class Book
{
public:
   String^ BookName;
   int BookNumber;
};

void SerializeObject( String^ studentFilename, String^ bookFilename
 )
{
   XmlSerializer^ mySerializer;
   TextWriter^ writer;

   // Create the XmlAttributeOverrides and XmlAttributes objects.
   XmlAttributeOverrides^ myXmlAttributeOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ myXmlAttributes = gcnew XmlAttributes;

   /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
   XmlAttributeAttribute^ myXmlAttributeAttribute = gcnew XmlAttributeAttribute;
   myXmlAttributeAttribute->AttributeName = "Name";
   myXmlAttributes->XmlAttribute = myXmlAttributeAttribute;

   // Add to the XmlAttributeOverrides. Specify the member name.
   myXmlAttributeOverrides->Add( Student::typeid, "StudentName", myXmlAttributes
 );

   // Create the XmlSerializer.
   mySerializer = gcnew XmlSerializer( Student::typeid,myXmlAttributeOverrides );
   writer = gcnew StreamWriter( studentFilename );

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

   // Set the Name property, which will be generated as an XML attribute.
 
   myStudent->StudentName = "James";
   myStudent->StudentNumber = 1;

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

   // Create the XmlAttributeOverrides and XmlAttributes objects.
   XmlAttributeOverrides^ myXmlBookAttributeOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ myXmlBookAttributes = gcnew XmlAttributes;

   /* Create an XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
   XmlAttributeAttribute^ myXmlBookAttributeAttribute = gcnew XmlAttributeAttribute(
 "Name" );
   myXmlBookAttributes->XmlAttribute = myXmlBookAttributeAttribute;

   // Add to the XmlAttributeOverrides. Specify the member name.
   myXmlBookAttributeOverrides->Add( Book::typeid, "BookName", myXmlBookAttributes
 );

   // Create the XmlSerializer.
   mySerializer = gcnew XmlSerializer( Book::typeid,myXmlBookAttributeOverrides );
   writer = gcnew StreamWriter( bookFilename );

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

   // Set the Name property, which will be generated as an XML attribute.
 
   myBook->BookName = ".NET";
   myBook->BookNumber = 10;

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

int main()
{
   SerializeObject(  "Student.xml",  "Book.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;

// This is the class that will be serialized.
public class Student
{
    public String studentName;
    public int studentNumber;
} //Student

public class Book
{
    public String bookName;
    public int bookNumber;
} //Book

public class XmlAttributeAttribute_Ctr1
{
    public static void main(String[]
 args)
    {
        XmlAttributeAttribute_Ctr1 myAttribute =
            new XmlAttributeAttribute_Ctr1();
        myAttribute.SerializeObject("Student.xml", "Book.xml");
    } //main

    public void SerializeObject(String studentfileName,
 String bookfileName)
    {
        XmlSerializer mySerializer;
        TextWriter writer;
        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides myXmlAttributeOverrides =
            new XmlAttributeOverrides();
        XmlAttributes myXmlAttributes = new XmlAttributes();

        /* Create an XmlAttributeAttribute set it to 
           the XmlAttribute property of the XmlAttributes object.
         */
        XmlAttributeAttribute myXmlAttributeAttribute = 
            new XmlAttributeAttribute();
        myXmlAttributeAttribute.set_AttributeName("Name");
        myXmlAttributes.set_XmlAttribute(myXmlAttributeAttribute);
        // Add to the XmlAttributeOverrides. Specify the member name.
        myXmlAttributeOverrides.Add(Student.class.ToType(), "studentName"
,
            myXmlAttributes);
        // Create the XmlSerializer.
        mySerializer = new XmlSerializer(Student.class.ToType()
,
            myXmlAttributeOverrides);

        writer = new StreamWriter(studentfileName);
        // Create an instance of the class that will be serialized.
        Student myStudent = new Student();
        // Set the Name property, which will be generated as an XML attribute.
 
        myStudent.studentName = "James";
        myStudent.studentNumber = 1;
        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myStudent);
        writer.Close();
        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides myXmlBookAttributeOverrides = 
            new XmlAttributeOverrides();
        XmlAttributes myXmlBookAttributes = new XmlAttributes();

        /* Create an XmlAttributeAttribute set it to 
           the XmlAttribute property of the XmlAttributes object.
         */
        XmlAttributeAttribute myXmlBookAttributeAttribute = 
            new XmlAttributeAttribute("Name");
        myXmlBookAttributes.set_XmlAttribute(myXmlBookAttributeAttribute);
        // Add to the XmlAttributeOverrides. Specify the member name.
        myXmlBookAttributeOverrides.Add(Book.class.ToType(), "BookName",
 
            myXmlBookAttributes);
        // Create the XmlSerializer.
        mySerializer = new XmlSerializer(Book.class.ToType()
,
            myXmlBookAttributeOverrides);

        writer = new StreamWriter(bookfileName);
        // Create an instance of the class that will be serialized.
        Book myBook = new Book();
        // Set the Name property, which will be generated as an XML attribute.
 
        myBook.bookName = ".NET";
        myBook.bookNumber = 10;
        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myBook);
        writer.Close();
    } //SerializeObject 
} //XmlAttributeAttribute_Ctr1
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAttributeAttribute クラス
XmlAttributeAttribute メンバ
System.Xml.Serialization 名前空間

XmlAttributeAttribute コンストラクタ

XmlAttributeAttribute クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
XmlAttributeAttribute () XmlAttributeAttribute クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

XmlAttributeAttribute (String) XmlAttributeAttribute クラス新しインスタンス初期化し生成されXML 属性の名前を指定します

.NET Compact Framework によってサポートされています。

XmlAttributeAttribute (Type) XmlAttributeAttribute クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

XmlAttributeAttribute (String, Type) XmlAttributeAttribute クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

XmlAttributeAttribute クラス
XmlAttributeAttribute メンバ
System.Xml.Serialization 名前空間

XmlAttributeAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。 ( Attribute から継承されます。)
参照参照

関連項目

XmlAttributeAttribute クラス
System.Xml.Serialization 名前空間

XmlAttributeAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlAttributeAttribute クラス
System.Xml.Serialization 名前空間

XmlAttributeAttribute メンバ

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

XmlAttributeAttribute データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XmlAttributeAttribute オーバーロードされます。 XmlAttributeAttribute クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlAttributeAttribute クラス
System.Xml.Serialization 名前空間


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

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

辞書ショートカット

すべての辞書の索引

「XmlAttributeAttribute」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS