XmlAnyElementAttribute 클래스

정의

멤버(XmlElement 또는 XmlNode 개체의 배열을 반환하는 필드)가 직렬 또는 역직렬화되고 있는 개체에 해당 멤버가 없는 XML 요소를 나타내는 개체를 포함하도록 지정합니다.

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

예제

다음 예에서는 개체의 XmlAnyElementAttribute 배열 XmlElement 을 반환하는 라는 AllElements 필드에 를 적용합니다.

public ref class XClass
{
public:

   /* Apply the XmlAnyElementAttribute to a field returning an array
      of XmlElement objects. */

   [XmlAnyElement]
   array<XmlElement^>^AllElements;
};

public ref class Test
{
public:
   void DeserializeObject( String^ filename )
   {
      // Create an XmlSerializer.
      XmlSerializer^ mySerializer = gcnew XmlSerializer( XClass::typeid );

      // To read a file, a FileStream is needed.
      FileStream^ fs = gcnew FileStream( filename,FileMode::Open );

      // Deserialize the class.
      XClass^ x = dynamic_cast<XClass^>(mySerializer->Deserialize( fs ));

      // Read the element names and values.
      System::Collections::IEnumerator^ myEnum = x->AllElements->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         XmlElement^ xel = safe_cast<XmlElement^>(myEnum->Current);
         Console::WriteLine( "{0}: {1}", xel->LocalName, xel->Value );
      }
   }
};

int main()
{
   Test^ t = gcnew Test;
   t->DeserializeObject( "XFile.xml" );
}
public class XClass
{
   /* Apply the XmlAnyElementAttribute to a field returning an array
   of XmlElement objects. */
   [XmlAnyElement]
   public XmlElement[] AllElements;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.DeserializeObject("XFile.xml");
   }

   private void DeserializeObject(string filename)
   {
      // Create an XmlSerializer.
      XmlSerializer mySerializer = new XmlSerializer(typeof(XClass));

      // To read a file, a FileStream is needed.
      FileStream fs = new FileStream(filename, FileMode.Open);

      // Deserialize the class.
      XClass x = (XClass) mySerializer.Deserialize(fs);

      // Read the element names and values.
      foreach(XmlElement xel in x.AllElements)
         Console.WriteLine(xel.LocalName + ": " + xel.Value);
   }
}
Public Class XClass
    ' Apply the XmlAnyElementAttribute to a field returning an array
    ' of XmlElement objects.
    <XmlAnyElement()> Public AllElements() As XmlElement
End Class


Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        t.DeserializeObject("XFile.xml")
    End Sub
    
    
    Private Sub DeserializeObject(filename As String)
        ' Create an XmlSerializer.
        Dim mySerializer As New XmlSerializer(GetType(XClass))
        
        ' To read a file, a FileStream is needed.
        Dim fs As New FileStream(filename, FileMode.Open)
        
        ' Deserialize the class.
        Dim x As XClass = CType(mySerializer.Deserialize(fs), XClass)
        
        ' Read the element names and values.
        Dim xel As XmlElement
        For Each xel In  x.AllElements
            Console.WriteLine((xel.LocalName & ": " & xel.Value))
        Next xel
    End Sub
End Class

설명

Silverlight, Windows Phone 또는 Windows 스토어 앱 프로젝트와 같은 이식 가능한 클래스 라이브러리에서 작업하고 .NET Framework 4.0.3 이상을 사용하는 경우 및 XmlNode대신 XmlElement 또는 XNode 를 사용합니다XElement.

XmlAnyElementAttribute 를 사용하여 문서의 일부로 전송된 메타데이터와 같이 XML 문서의 일부로 보낼 수 있는 임의의 데이터(XML 요소)를 포함합니다.

XmlAnyElementAttribute 또는 XmlNode 개체의 배열을 반환하는 필드에 를 XmlElement 적용합니다. 이러한 필드는 개체가 직렬화 또는 역직렬화되는지 여부에 따라 두 가지 방법으로 사용할 수 있습니다. serialize할 때 개체는 직렬화되는 개체에 해당 멤버(또는 멤버)가 없더라도 XML 요소 또는 노드로 생성됩니다. 특성을 적용할 때 속성 값을 지정 Name 하면 배열에 삽입된 모든 XmlElement 또는 XmlNode 개체에 동일한 요소 이름과 기본 네임스페이스가 있어야 합니다. 그렇지 않으면 예외가 throw됩니다. 속성 값을 설정하는 Namespace 경우 속성도 설정 Name 해야 하며 XmlElement 또는 XmlNode 개체도 이름과 네임스페이스 값이 같아야 합니다. 값을 지정하지 Name 않으면 또는 XmlNode 개체에 XmlElement 요소 이름이 있을 수 있습니다.

클래스의 메서드를 DeserializeXmlSerializer 호출하면 역직렬화되는 개체에 해당 멤버가 없는 모든 요소가 배열에서 수집됩니다. 역직렬화 후 항목 컬렉션을 XmlElement 반복하여 데이터를 처리합니다. 값을 지정 Name 하는 경우 배열에는 해당 이름의 XML 요소만 포함됩니다. 값을 지정 Name 하지 않으면 배열에는 클래스에 해당 멤버가 없는 모든 요소가 포함됩니다. 클래스에 특성이 적용되는 필드가 둘 이상 포함된 경우 , 또는 NameNamespace 속성을 사용하여 Name배열의 내용을 구분합니다. 이러한 클래스(여러 필드 포함)에도 역직렬화 중에 구분 속성 값이 설정되지 않은 필드가 하나(즉, NameNamespace)인 경우 이 배열에는 다른 배열에 아직 포함되지 않은 알 수 없는 XML 요소가 포함됩니다. 클래스에 구분 Name되는 , 또는 NameNamespace 값 집합이 없는 둘 이상의 필드가 포함된 경우 역직렬화 중 동작은 지정되지 않습니다.

단일 XmlElement 개체를 반환하는 필드에 를 XmlAnyElementAttribute 적용할 수도 있습니다. 이렇게 하면 클래스의 속성과 메서드를 XmlElement 사용하여 알 수 없는 요소를 재귀적으로 반복해야 합니다.

의 여러 인스턴스를 XmlAnyElementAttribute 클래스 멤버에 적용할 수 있지만 각 instance 고유한 Name 속성 값이 있어야 합니다. 또는 각 instance 대해 동일한 Name 속성이 설정된 경우 각 instance 대해 고유한 Namespace 속성 값을 설정해야 합니다.

UnknownNode 클래스의 멤버에 를 XmlSerializer 적용 XmlAnyElementAttribute 하면 의 및 UnknownAttribute 이벤트가 발생하지 않습니다.

참고

더 긴 XmlAnyElementAttribute대신 코드에서 단어를 XmlAnyElement 사용할 수 있습니다.

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

생성자

XmlAnyElementAttribute()

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

XmlAnyElementAttribute(String)

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

XmlAnyElementAttribute(String, String)

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

속성

Name

XML 요소 이름을 가져오거나 설정합니다.

Namespace

XML 문서에 생성된 XML 네임스페이스를 가져오거나 설정합니다.

Order

요소가 직렬화 또는 역직렬화되는 명시적 순서를 가져오거나 설정합니다.

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)

적용 대상

추가 정보