XmlAttributeAttribute 클래스

정의

XmlSerializer가 해당 클래스 멤버를 XML 특성으로 serialize하도록 지정합니다.

public ref class XmlAttributeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue)]
public class XmlAttributeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue)>]
type XmlAttributeAttribute = class
    inherit Attribute
Public Class XmlAttributeAttribute
Inherits Attribute
상속
XmlAttributeAttribute
특성

예제

다음 예제에서는 적용되는 여러 필드가 포함된 클래스를 XmlAttributeAttribute serialize합니다.

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

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

설명

개체 XmlAttributeAttribute 를 직렬화하거나 역직렬화하는 방법을 XmlSerializer 제어하는 특성 패밀리에 속합니다. 유사한 특성의 전체 목록은 XML Serialization을 제어하는 특성을 참조하세요.

공용 필드 또는 속성 XmlAttributeAttribute 에 적용하면 멤버를 XML 특성으로 serialize하도록 알릴 XmlSerializer 수 있습니다. 기본적으로 공용 XmlSerializer 필드와 속성을 XML 요소로 직렬화합니다.

XSD 형식에서 파생된 모든 기본 제공 데이터 형식을 포함하여 XSD(XML 스키마 정의 언어) 단순 형식 중 하나에 매핑할 수 있는 값(또는 값 배열)을 반환하는 공용 필드 또는 공용 속성에 anySimpleType 만 할당 XmlAttributeAttribute 할 수 있습니다. 가능한 형식에는 XSD 단순 형식(예: 열Char거형)Guid에 매핑할 수 있는 모든 형식이 포함됩니다. DataType XSD 형식 목록 및 데이터 형식을 to.NET 매핑하는 방법은 속성을 참조하세요.

(언어 지정) 및 xml:space (공백 처리 방법 지정) 특성으로 xml:lang XmlAttributeAttribute 설정할 수 있는 두 가지 특수 특성이 있습니다. 이러한 특성은 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 
<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()

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

XmlAttributeAttribute(String)

XmlAttributeAttribute 클래스의 새 인스턴스를 초기화하고 생성된 XML 특성의 이름을 지정합니다.

XmlAttributeAttribute(String, Type)

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

XmlAttributeAttribute(Type)

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

속성

AttributeName

XML 특성의 이름을 가져오거나 설정합니다.

DataType

XmlSerializer에 의해 생성된 XML 특성의 XSD 데이터 형식을 가져오거나 설정합니다.

Form

XmlSerializer를 통해 생성된 XML 특성의 이름이 정규화된 이름인지 여부를 나타내는 값을 가져오거나 설정합니다.

Namespace

XML 특성의 XML 네임스페이스를 가져오거나 설정합니다.

Type

XML 특성의 복합 형식을 가져오거나 설정합니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상