다음을 통해 공유


XmlAttributeAttribute 클래스

정의

XmlSerializer 클래스 멤버를 XML 특성으로 직렬화하도록 지정합니다.

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

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

생성자

Name Description
XmlAttributeAttribute()

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

XmlAttributeAttribute(String, Type)

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

XmlAttributeAttribute(String)

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

XmlAttributeAttribute(Type)

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

속성

Name Description
AttributeName

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

DataType

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

Form

XML 특성 이름이 XmlSerializer 정규화되어 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

Namespace

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

Type

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

TypeId

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

(다음에서 상속됨 Attribute)

메서드

Name Description
Equals(Object)

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

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

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

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

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

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

파생 클래스에서 재정의되는 경우 이 인스턴스의 값이 파생 클래스의 기본값인지 여부를 나타냅니다.

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

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

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

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

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

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

Name Description
_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)

적용 대상