XmlAttributeAttribute コンストラクタとは? わかりやすく解説

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

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 コンストラクタ ()

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



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

辞書ショートカット

すべての辞書の索引

「XmlAttributeAttribute コンストラクタ」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS