Share via


XmlArrayAttribute 생성자

정의

XmlArrayAttribute 클래스의 새 인스턴스를 초기화합니다.

오버로드

XmlArrayAttribute()

XmlArrayAttribute 클래스의 새 인스턴스를 초기화합니다.

XmlArrayAttribute(String)

XmlArrayAttribute 클래스의 새 인스턴스를 초기화하며 XML 문서 인스턴스에서 생성된 XML 요소의 이름을 지정합니다.

XmlArrayAttribute()

Source:
XmlArrayAttribute.cs
Source:
XmlArrayAttribute.cs
Source:
XmlArrayAttribute.cs

XmlArrayAttribute 클래스의 새 인스턴스를 초기화합니다.

public:
 XmlArrayAttribute();
public XmlArrayAttribute ();
Public Sub New ()

예제

다음 예제에서는 두 배열에 를 XmlArrayAttribute 할당합니다.

public ref class MyClass
{
public:

   [XmlArrayAttribute]
   array<String^>^MyStringArray;

   [XmlArrayAttribute]
   array<Int32>^MyIntegerArray;
};
public class MyClass
{
    [XmlArrayAttribute()]
    public string [] MyStringArray;
    [XmlArrayAttribute()]
    public int [] MyIntegerArray;
}
Public Class MyClass1
    <XmlArrayAttribute()> Public MyStringArray() As String
    <XmlArrayAttribute()> Public MyIntegerArray() As Integer
End Class

설명

특성을 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 특성합니다.

추가 정보

적용 대상

XmlArrayAttribute(String)

Source:
XmlArrayAttribute.cs
Source:
XmlArrayAttribute.cs
Source:
XmlArrayAttribute.cs

XmlArrayAttribute 클래스의 새 인스턴스를 초기화하며 XML 문서 인스턴스에서 생성된 XML 요소의 이름을 지정합니다.

public:
 XmlArrayAttribute(System::String ^ elementName);
public XmlArrayAttribute (string elementName);
public XmlArrayAttribute (string? elementName);
new System.Xml.Serialization.XmlArrayAttribute : string -> System.Xml.Serialization.XmlArrayAttribute
Public Sub New (elementName As String)

매개 변수

elementName
String

XmlSerializer가 생성하는 XML 요소의 이름입니다.

예제

다음 예제에서는 를 두 배열에 할당 XmlArrayAttribute 하고 해당 배열을 포함하는 클래스 인스턴스를 serialize합니다.

#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();
}
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();
   }
}
Option Explicit
Option Strict

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

<?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>

설명

특성을 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 특성합니다.

추가 정보

적용 대상