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

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

XmlArrayAttribute コンストラクタ (String)

XmlArrayAttribute クラス新しインスタンス初期化しXML ドキュメント インスタンス生成される XML 要素名を指定します

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

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

Dim instance As New XmlArrayAttribute(elementName)
public XmlArrayAttribute (
    string elementName
)
public:
XmlArrayAttribute (
    String^ elementName
)
public XmlArrayAttribute (
    String elementName
)
public function XmlArrayAttribute (
    elementName : String
)

パラメータ

elementName

XmlSerializer が生成する XML 要素の名前。

解説解説
使用例使用例

XmlArrayAttribute2 つ配列代入し、これらの配列を含むクラス インスタンスシリアル化する例を次に示します

Option Explicit
Option Strict

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


Public Class MyClass1
    <XmlArrayAttribute("MyStrings")> _
        Public MyStringArray() As String

    <XmlArrayAttribute(ElementName := "MyIntegers")>
 _
        Public MyIntegerArray() As Integer
End Class


Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        test.SerializeObject("MyClass.xml")
    End Sub    
    
    Public Sub SerializeObject(ByVal
 filename As String)
        ' Creates a new instance of the XmlSerializer class.
        Dim s As New XmlSerializer(GetType(MyClass1))
        ' Needed a StreamWriter to write the file.
        Dim myWriter As New
 StreamWriter(filename)
        
        Dim class1 As New
 MyClass1()
        ' Creates and populates a string array, then assigns
        ' it to the MyStringArray property.
        Dim myStrings() As String
 =  {"Hello", "World",
 "!"}
        class1.MyStringArray = myStrings
        ' Creates and populates an integer array, and assigns
        ' it to the MyIntegerArray property.
        Dim myIntegers() As Integer
 =  {1, 2, 3}
        class1.MyIntegerArray = myIntegers
        ' Serializes the class, and writes it to disk.
        s.Serialize(myWriter, class1)
        myWriter.Close()
    End Sub
End Class

using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
 
public class MyClass{
   [XmlArrayAttribute("MyStrings")]
   public string [] MyStringArray;
   [XmlArrayAttribute(ElementName = "MyIntegers")]
   public int [] MyIntegerArray;
}
 
public class Run{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("MyClass.xml");
   }
 
   public void SerializeObject(string
 filename)
   {
      // Creates a new instance of the XmlSerializer class.
      XmlSerializer s = new XmlSerializer(typeof(MyClass));
      // Needs a StreamWriter to write the file.
      TextWriter myWriter= new StreamWriter(filename);
 
      MyClass myClass = new MyClass();
      // Creates and populates a string array, then assigns
      // it to the MyStringArray property.
      string [] myStrings = {"Hello", "World",
 "!"};
      myClass.MyStringArray = myStrings;
      /* Creates and populates an integer array, and assigns
      it to the MyIntegerArray property. */
      int [] myIntegers = {1,2,3};
      myClass.MyIntegerArray = myIntegers;     
      // Serializes the class, and writes it to disk.
      s.Serialize(myWriter, myClass);
      myWriter.Close();
   }
}

#using <System.Xml.dll>
#using <System.dll>

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

public ref class MyClass
{
public:

   [XmlArrayAttribute("MyStrings")]
   array<String^>^MyStringArray;

   [XmlArrayAttribute(ElementName="MyIntegers")]
   array<Int32>^MyIntegerArray;
};

int main()
{
   String^ filename = "MyClass.xml";

   // Creates a new instance of the XmlSerializer class.
   XmlSerializer^ s = gcnew XmlSerializer( MyClass::typeid );

   // Needs a StreamWriter to write the file.
   TextWriter^ myWriter = gcnew StreamWriter( filename );
   MyClass^ myClass = gcnew MyClass;

   // Creates and populates a string array, then assigns
   // it to the MyStringArray property.
   array<String^>^myStrings = {"Hello","World","!"};
   myClass->MyStringArray = myStrings;

   /* Creates and populates an integer array, and assigns
      it to the MyIntegerArray property. */
   array<Int32>^myIntegers = {1,2,3};
   myClass->MyIntegerArray = myIntegers;

   // Serializes the class, and writes it to disk.
   s->Serialize( myWriter, myClass );
   myWriter->Close();
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;

public class MyClass
{
    /** @attribute XmlArrayAttribute("MyStrings")
     */
    public String myStringArray[];

    /** @attribute XmlArrayAttribute(ElementName = "MyIntegers")
     */
    public int myIntegerArray[];
} //MyClass

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

    public void SerializeObject(String fileName)
    {
        // Creates a new instance of the XmlSerializer class.
        XmlSerializer s = new XmlSerializer(MyClass.class.ToType());

        // Needs a StreamWriter to write the file.
        TextWriter myWriter = new StreamWriter(fileName);
        MyClass myClass = new MyClass();

        // Creates and populates a string array, then assigns
        // it to the MyStringArray property.
        String myStrings[] =  { "Hello", "World", "!"
 };
        myClass.myStringArray = myStrings;

        /* Creates and populates an integer array, and assigns
           it to the MyIntegerArray property. 
        */
        int myIntegers[] =  { 1, 2, 3 };
        myClass.myIntegerArray = myIntegers;

        // Serializes the class, and writes it to disk.
        s.Serialize(myWriter, myClass);
        myWriter.Close();
    } //SerializeObject
} //Run
<?xml version="1.0"?>
 <MyClass1 xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/1999/XMLSchema">
   <MyStrings>
     <string>Hello</string>
     <string>World</string>
     <string>!</string>
   </MyStrings>
   <MyIntegers>
     <int>1</int>
     <int>2</int>
     <int>3</int>
   </MyIntegers>
 </MyClass1>

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

XmlArrayAttribute コンストラクタ

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

参照参照

関連項目

XmlArrayAttribute クラス
XmlArrayAttribute メンバ
System.Xml.Serialization 名前空間
XmlArrayItemAttribute
XmlSerializer

XmlArrayAttribute コンストラクタ ()

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

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

Dim instance As New XmlArrayAttribute
public XmlArrayAttribute ()
public:
XmlArrayAttribute ()
public XmlArrayAttribute ()
public function XmlArrayAttribute ()
解説解説
使用例使用例

XmlArrayAttribute2 つ配列代入する例を次に示します

Public Class MyClass1
    <XmlArrayAttribute()> Public MyStringArray() As
 String
    <XmlArrayAttribute()> Public MyIntegerArray() As
 Integer
End Class

public class MyClass
{
    [XmlArrayAttribute()]
    public string [] MyStringArray;
    [XmlArrayAttribute()]
    public int [] MyIntegerArray;
}

public ref class MyClass
{
public:

   [XmlArrayAttribute]
   array<String^>^MyStringArray;

   [XmlArrayAttribute]
   array<Int32>^MyIntegerArray;
};

public class MyClass
{
    /** @attribute XmlArrayAttribute()
     */
    public String myStringArray[];

    /** @attribute XmlArrayAttribute()
     */
    public int myIntegerArray[];
} //MyClass
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlArrayAttribute クラス
XmlArrayAttribute メンバ
System.Xml.Serialization 名前空間
XmlArrayItemAttribute
XmlSerializer


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS