XmlAttributeAttribute クラス
アセンブリ: System.Xml (system.xml.dll 内)

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue)> _ Public Class XmlAttributeAttribute Inherits Attribute
[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

XmlAttributeAttribute は、XmlSerializer がオブジェクトをシリアル化または逆シリアル化する方法を制御する一連の属性に属します。類似する属性の完全な一覧については、「XML シリアル化を制御する属性」を参照してください。
XmlAttributeAttribute は、パブリック フィールドまたはパブリック プロパティに適用された場合、それらのフィールドやプロパティを XML 属性としてシリアル化するように XmlSerializer に通知します。既定では、XmlSerializer は、パブリック フィールドまたはパブリック プロパティを XML 要素としてシリアル化します。
XmlAttributeAttribute は、XML スキーマ定義言語 (XSD) の単純型 (anySimpleType 型から派生した組み込みデータ型を含む) の 1 つに割り当てることができる値または値の配列を返す、パブリック フィールドまたはパブリック プロパティにだけ割り当てることができます。Guid、Char、列挙体など、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.Attribute
System.Xml.Serialization.XmlAttributeAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlAttributeAttribute コンストラクタ ()
アセンブリ: System.Xml (system.xml.dll 内)


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

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlAttributeAttribute コンストラクタ (String, Type)
アセンブリ: System.Xml (system.xml.dll 内)

Dim attributeName As String Dim type As Type Dim instance As New XmlAttributeAttribute(attributeName, type)

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlAttributeAttribute コンストラクタ (Type)
アセンブリ: System.Xml (system.xml.dll 内)


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlAttributeAttribute コンストラクタ (String)
アセンブリ: System.Xml (system.xml.dll 内)


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

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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 メソッド

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

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

XmlAttributeAttribute メンバ
XmlSerializer がクラス メンバを XML 属性としてシリアル化する必要があることを指定します。
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 から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からXmlAttributeAttributeを検索する場合は、下記のリンクをクリックしてください。

- XmlAttributeAttributeのページへのリンク