XmlAnyElementAttributes 클래스

정의

XmlAnyElementAttribute 개체의 컬렉션을 나타냅니다.

public ref class XmlAnyElementAttributes : System::Collections::IList
public ref class XmlAnyElementAttributes : System::Collections::CollectionBase
public class XmlAnyElementAttributes : System.Collections.IList
public class XmlAnyElementAttributes : System.Collections.CollectionBase
type XmlAnyElementAttributes = class
    interface ICollection
    interface IEnumerable
    interface IList
type XmlAnyElementAttributes = class
    inherit CollectionBase
Public Class XmlAnyElementAttributes
Implements IList
Public Class XmlAnyElementAttributes
Inherits CollectionBase
상속
XmlAnyElementAttributes
상속
XmlAnyElementAttributes
구현

예제

다음 예제에서는 새로 XmlAnyElementAttribute 만들고 속성을 통해 액세스 하는 개체의 컬렉션에 XmlAnyElements 추가 합니다. 그런 다음 , XmlAttributesXmlAttributeOverrides 만드는 데 사용되는 항목에 추가됩니다 XmlSerializer. XmlSerializer 직렬화하거나 개체를 역직렬화하는 데 사용 됩니다. 속성을 사용하는 XmlAnyElementAttributes 효과를 보려면 메서드에서 메서드 Main 를 실행 SerializeObject 하여 UnknownElements.xml XML 문서를 만듭니다. (알 수 없는) 다른 요소를 포함 하려면 결과 문서를 편집 합니다. 주석으로 처리를 SerializeObject 에서 호출 합니다 Main 메서드를에 대 한 호출을 주석 처리 제거를 DeserializeObject 이름과 알 수 없는 XML 요소의 값을 출력 하는 메서드를 합니다.

#using <System.dll>
#using <System.xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Xml;
public ref class Group
{
public:
   String^ GroupName;

   [XmlAnyElement]
   array<Object^>^Things;
};

void SerializeObject( String^ filename );
void DeserializeObject( String^ filename );
XmlSerializer^ CreateOverrideSerializer();
int main()
{
   // 1 Run this and create the XML document.
   // 2 Add new elements to the XML document.
   // 3 Comment out the next line, and uncomment
   // the DeserializeObject line to deserialize the
   // XML document and see unknown elements.
   SerializeObject( "UnknownElements.xml" );

   // DeserializeObject(S"UnknownElements.xml");
}

void SerializeObject( String^ filename )
{
   XmlSerializer^ ser = gcnew XmlSerializer( Group::typeid );
   TextWriter^ writer = gcnew StreamWriter( filename );
   Group^ g = gcnew Group;
   g->GroupName = "MyGroup";
   ser->Serialize( writer, g );
   writer->Close();
}

void DeserializeObject( String^ filename )
{
   XmlSerializer^ ser = CreateOverrideSerializer();

   // A FileStream is needed to read the XML document.
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   Group^ g = safe_cast<Group^>(ser->Deserialize( fs ));
   fs->Close();
   Console::WriteLine( g->GroupName );
   Console::WriteLine( g->Things->Length );
   for ( int i = 0; i < g->Things->Length; ++i )
   {
      XmlElement^ xelement = safe_cast<XmlElement^>(g->Things[ i ]);
      Console::WriteLine( "{0}: {1}", xelement->Name, xelement->InnerXml );
   }
}

XmlSerializer^ CreateOverrideSerializer()
{
   XmlAnyElementAttribute^ myAnyElement = gcnew XmlAnyElementAttribute;
   XmlAttributeOverrides^ xOverride = gcnew XmlAttributeOverrides;
   XmlAttributes^ xAtts = gcnew XmlAttributes;
   xAtts->XmlAnyElements->Add( myAnyElement );
   xOverride->Add( Group::typeid, "Things", xAtts );
   return gcnew XmlSerializer( Group::typeid,xOverride );
}
using System;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

public class Group{
   public string GroupName;
   [XmlAnyElement]
   public object[]Things;
}

public class Test{
   static void Main(){
      Test t = new Test();
      // 1 Run this and create the XML document.
      // 2 Add new elements to the XML document.
      // 3 Comment out the new line, and uncomment
      // the DeserializeObject line to deserialize the
      // XML document and see unknown elements.
      t.SerializeObject("UnknownElements.xml");
     
      // t.DeserializeObject("UnknownElements.xml");
   }

   private void SerializeObject(string filename){
      XmlSerializer ser = new XmlSerializer(typeof (Group));
      TextWriter writer = new StreamWriter(filename);
      Group g = new Group();
      g.GroupName = "MyGroup";
      ser.Serialize(writer, g);
      writer.Close();
   }

   private void DeserializeObject(string filename){

      XmlSerializer ser = CreateOverrideSerializer();
      // A FileStream is needed to read the XML document.
      FileStream fs = new FileStream(filename, FileMode.Open);
     Group g = (Group)
        ser.Deserialize(fs);
     fs.Close();
     Console.WriteLine(g.GroupName);
     Console.WriteLine(g.Things.Length);
     foreach(XmlElement xelement in g.Things){
     Console.WriteLine(xelement.Name + ": " + xelement.InnerXml);
     }
   }

   private XmlSerializer CreateOverrideSerializer(){
      XmlAnyElementAttribute myAnyElement = 
      new XmlAnyElementAttribute();
      XmlAttributeOverrides xOverride = 
      new XmlAttributeOverrides();
      XmlAttributes xAtts = new XmlAttributes();
      xAtts.XmlAnyElements.Add(myAnyElement);
      xOverride.Add(typeof(Group), "Things", xAtts);
      return new XmlSerializer(typeof(Group) , xOverride);
   }
}
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml

Public Class Group
   Public GroupName As String 
   <XmlAnyElement> _
   Public Things () As object
End Class

Public Class Test
   Shared Sub Main()
      Dim t As Test = New Test()
      ' 1 Run this and create the XML document.
      ' 2 Add New elements to the XML document.
      ' 3 Comment out the New line, and uncomment
      ' the DeserializeObject line to deserialize the
      ' XML document and see unknown elements.
     t.SerializeObject("UnknownElements.xml")
     
      't.DeserializeObject("UnknownElements.xml")
   End Sub

   Private Sub SerializeObject(filename As String)
      Dim ser As XmlSerializer = New XmlSerializer(GetType (Group))
      Dim writer As TextWriter = New StreamWriter(filename)
      
      Dim g As Group = New Group()
      g.GroupName = "MyGroup"
      ser.Serialize(writer, g)
      writer.Close()
   End Sub

   
   Private Sub DeserializeObject(filename As String)

      Dim ser As XmlSerializer = CreateOverrideSerializer()
      ' A FileStream is needed to read the XML document.
      Dim fs As FileStream = New FileStream(filename, FileMode.Open)
     Dim g As Group = CType( _
        ser.Deserialize(fs), Group)
     fs.Close()
     Console.WriteLine(g.GroupName)
     Console.WriteLine(g.Things.Length)
     Dim xelement As XmlELement
     for each xelement in g.Things
        Console.WriteLine(xelement.Name &": " & xelement.InnerXml)
     next
   End Sub
   

   Private Function CreateOverrideSerializer() As XmlSerializer 
      Dim myAnyElement As XmlAnyElementAttribute = _
      New XmlAnyElementAttribute()
      Dim xOverride As XmlAttributeOverrides = _
      New XmlAttributeOverrides()
      Dim xAtts As XmlAttributes = New XmlAttributes()
      xAtts.XmlAnyElements.Add(myAnyElement)
      xOverride.Add(GetType(Group), "Things", xAtts)
      return New XmlSerializer(GetType(Group) , xOverride)
   End Function
End Class

설명

XmlAnyElementAttributes 개체 집합의 동작을 재정의 XmlAnyElementAttribute 하는 데 사용합니다. 각 인스턴스 XmlAnyElementAttribute 에 고유한 Name 속성 값이 있는 한 클래스의 여러 인스턴스를 클래스 멤버에 적용할 수 있습니다. 이렇게 하면 명명된 요소 아래에 있는 알 수 없는 요소를 적절한 배열로 수집하도록 지시 XmlSerializer 합니다. 이러한 이유로 클래스의 여러 인스턴스를 XmlAnyElementAttribute 추가할 수 XmlAnyElementAttributes있습니다.

개체 집합을 재정의하려면 다음을 XmlAnyElementAttribute 수행합니다.

  1. 를 만듭니다 XmlAnyElementAttributes.

  2. 개체 집합 XmlAnyElementAttribute 을 만들고 메서드를 사용하여 컬렉션에 각 개체를 Add 추가합니다.

  3. 를 만듭니다 XmlAttributes.

  4. 속성을 .로 XmlAnyElements XmlAnyElementAttributes설정합니다.

  5. 를 만듭니다 XmlAttributeOverrides.

  6. 추가 합니다 XmlAttributesXmlAttributeOverrides 사용 하 여를 Add 메서드.

  7. 를 사용하여 인스턴스 XmlSerializer 를 만듭니다 XmlAttributeOverrides.

  8. 개체 집합 XmlAnyElementAttribute 이 포함된 개체를 직렬화하거나 역직렬화합니다.

생성자

XmlAnyElementAttributes()

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

속성

Capacity

CollectionBase에 포함될 수 있는 요소의 수를 가져오거나 설정합니다.

(다음에서 상속됨 CollectionBase)
Count

ICollection에 포함된 요소 수를 가져옵니다.

Count

CollectionBase 인스턴스에 포함된 요소 수를 가져옵니다. 이 속성은 재정의할 수 없습니다.

(다음에서 상속됨 CollectionBase)
InnerList

ArrayList 인스턴스의 요소 목록을 포함하는 CollectionBase를 가져옵니다.

(다음에서 상속됨 CollectionBase)
Item[Int32]

지정된 인덱스에 있는 XmlAnyElementAttribute를 가져오거나 설정합니다.

List

IList 인스턴스의 요소 목록을 포함하는 CollectionBase를 가져옵니다.

(다음에서 상속됨 CollectionBase)

메서드

Add(XmlAnyElementAttribute)

XmlAnyElementAttribute을 컬렉션에 추가합니다.

Clear()

IList에서 항목을 모두 제거합니다.

Clear()

CollectionBase 인스턴스에서 개체를 모두 제거합니다. 이 메서드는 재정의할 수 없습니다.

(다음에서 상속됨 CollectionBase)
Contains(XmlAnyElementAttribute)

지정된 XmlAnyElementAttribute가 컬렉션에 있는지 여부를 나타내는 값을 가져옵니다.

CopyTo(XmlAnyElementAttribute[], Int32)

대상 배열의 지정된 인덱스에서 시작하여 전체 컬렉션을 호환 가능한 XmlElementAttribute 개체의 1차원 배열에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

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

컬렉션을 반복하는 열거자를 반환합니다.

GetEnumerator()

CollectionBase 인스턴스를 반복하는 열거자를 반환합니다.

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

기본 해시 함수로 작동합니다.

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

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

(다음에서 상속됨 Object)
IndexOf(XmlAnyElementAttribute)

지정된 XmlAnyElementAttribute의 인덱스를 가져옵니다.

Insert(Int32, XmlAnyElementAttribute)

XmlAnyElementAttribute을 컬렉션에서 지정한 인덱스에 삽입합니다.

MemberwiseClone()

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

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

CollectionBase 인스턴스의 콘텐츠를 지운 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnClearComplete()

CollectionBase 인스턴스의 내용을 지운 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnInsert(Int32, Object)

CollectionBase 인스턴스에 새 요소를 삽입하기 전에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnInsertComplete(Int32, Object)

CollectionBase 인스턴스에 새 요소를 삽입한 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnRemove(Int32, Object)

CollectionBase 인스턴스에서 요소를 제거할 때 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnRemoveComplete(Int32, Object)

CollectionBase 인스턴스에서 요소를 제거한 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnSet(Int32, Object, Object)

CollectionBase 인스턴스에 값을 설정하기 전에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnSetComplete(Int32, Object, Object)

CollectionBase 인스턴스에 값을 설정한 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnValidate(Object)

값의 유효성을 검사할 때 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
Remove(XmlAnyElementAttribute)

지정된 XmlAnyElementAttribute를 컬렉션에서 제거합니다.

RemoveAt(Int32)

지정한 인덱스에서 IList 항목을 제거합니다.

RemoveAt(Int32)

CollectionBase 인스턴스의 지정한 인덱스에서 요소를 제거합니다. 이 메서드는 재정의할 수 없습니다.

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

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

ICollection의 요소를 배열의 특정 배열 인덱스에서 시작하는 위치에 복사합니다.

ICollection.CopyTo(Array, Int32)

대상 배열의 지정된 인덱스에서 시작하여 전체 CollectionBase을 호환되는 1차원 Array에 복사합니다.

(다음에서 상속됨 CollectionBase)
ICollection.IsSynchronized

ICollection에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

ICollection.IsSynchronized

CollectionBase에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

(다음에서 상속됨 CollectionBase)
ICollection.SyncRoot

ICollection에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

ICollection.SyncRoot

CollectionBase에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

(다음에서 상속됨 CollectionBase)
IList.Add(Object)

IList에 항목을 추가합니다.

IList.Add(Object)

개체를 CollectionBase의 끝 부분에 추가합니다.

(다음에서 상속됨 CollectionBase)
IList.Contains(Object)

IList에 특정 값이 들어 있는지 여부를 확인합니다.

IList.Contains(Object)

CollectionBase에 특정 요소가 들어 있는지 여부를 확인합니다.

(다음에서 상속됨 CollectionBase)
IList.IndexOf(Object)

IList에서 특정 항목의 인덱스를 결정합니다.

IList.IndexOf(Object)

지정한 Object를 검색하고, 전체 CollectionBase 내에서 처음 나오는 0부터 시작하는 인덱스를 반환합니다.

(다음에서 상속됨 CollectionBase)
IList.Insert(Int32, Object)

항목을 IList의 지정된 인덱스에 삽입합니다.

IList.Insert(Int32, Object)

CollectionBase의 지정된 인덱스에 요소를 삽입합니다.

(다음에서 상속됨 CollectionBase)
IList.IsFixedSize

IList의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IList.IsFixedSize

CollectionBase의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 CollectionBase)
IList.IsReadOnly

IList가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

IList.IsReadOnly

CollectionBase가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 CollectionBase)
IList.Item[Int32]

지정한 인덱스에 있는 요소를 가져오거나 설정합니다.

IList.Item[Int32]

지정한 인덱스에 있는 요소를 가져오거나 설정합니다.

(다음에서 상속됨 CollectionBase)
IList.Remove(Object)

IList에서 맨 처음 발견되는 특정 개체를 제거합니다.

IList.Remove(Object)

CollectionBase에서 맨 처음 발견되는 특정 개체를 제거합니다.

(다음에서 상속됨 CollectionBase)

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상