XmlTypeMapping 클래스

정의

한 형식과 다른 형식의 매핑을 포함합니다.

public ref class XmlTypeMapping : System::Xml::Serialization::XmlMapping
public class XmlTypeMapping : System.Xml.Serialization.XmlMapping
type XmlTypeMapping = class
    inherit XmlMapping
Public Class XmlTypeMapping
Inherits XmlMapping
상속
XmlTypeMapping

예제

다음 예제에서는 라는 클래스의 인스턴스를 serialize Transportation 라는 필드가 있는 Vehicle합니다. SoapElementAttribute 필드에 적용 됩니다. 필드도 serialize 될 때 XML 요소 이름은 "Vehicle" 대신 "바퀴"입니다. SerializeOverride 메서드를 만듭니다를 SoapElementAttribute 설정 및는 SoapElement 의 속성을 SoapAttributesSoapElementAttribute. SoapAttributes 에 추가 되는 SoapAttributeOverrides 만드는 데 사용 되는 XmlTypeMapping합니다. XmlSerializer 로 생성 된를 XmlTypeMapping의 인스턴스를 Transportation 클래스 다시 serialize 됩니다. 때문에 SoapElementAttribute 는 serialization을 재정의 하는 데, 생성 된 XML 요소 이름은 이제 "바퀴" 대신 "Truck".

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Collections;
using namespace System::Xml;
using namespace System::Text;
public ref class Thing
{
public:

   [SoapElement(IsNullable=true)]
   String^ ThingName;
};

public ref class Transportation
{
public:

   // The SoapElementAttribute specifies that the
   // generated XML element name will be S"Wheels"
   // instead of S"Vehicle".

   [SoapElement("Wheels")]
   String^ Vehicle;

   [SoapElement(DataType="dateTime")]
   DateTime CreationDate;

   [SoapElement(IsNullable=true)]
   Thing^ thing;
};

public ref class Test
{
public:

   // Return an XmlSerializer used for overriding.
   XmlSerializer^ CreateSoapOverrider()
   {
      // Create the SoapAttributes and SoapAttributeOverrides objects.
      SoapAttributes^ soapAttrs = gcnew SoapAttributes;
      SoapAttributeOverrides^ soapOverrides = gcnew SoapAttributeOverrides;

      // Create an SoapElementAttribute to the Vehicles property.
      SoapElementAttribute^ soapElement1 = gcnew SoapElementAttribute( "Truck" );

      // Set the SoapElement to the Object*.
      soapAttrs->SoapElement = soapElement1;

      // Add the SoapAttributes to the SoapAttributeOverrides,specifying the member to.
      soapOverrides->Add( Transportation::typeid, "Vehicle", soapAttrs );

      // Create the XmlSerializer, and return it.
      XmlTypeMapping^ myTypeMapping = (gcnew SoapReflectionImporter( soapOverrides ))->ImportTypeMapping( Transportation::typeid );
      return gcnew XmlSerializer( myTypeMapping );
   }

   void SerializeOverride( String^ filename )
   {
      // Create an XmlSerializer instance.
      XmlSerializer^ ser = CreateSoapOverrider();

      // Create the Object* and serialize it.
      Transportation^ myTransportation = gcnew Transportation;
      myTransportation->Vehicle = "MyCar";
      myTransportation->CreationDate = DateTime::Now;
      myTransportation->thing = gcnew Thing;
      XmlTextWriter^ writer = gcnew XmlTextWriter( filename,Encoding::UTF8 );
      writer->Formatting = Formatting::Indented;
      writer->WriteStartElement( "wrapper" );
      ser->Serialize( writer, myTransportation );
      writer->WriteEndElement();
      writer->Close();
   }

   void SerializeObject( String^ filename )
   {
      // Create an XmlSerializer instance.
      XmlSerializer^ ser = gcnew XmlSerializer( Transportation::typeid );
      Transportation^ myTransportation = gcnew Transportation;
      myTransportation->Vehicle = "MyCar";
      myTransportation->CreationDate = DateTime::Now;
      myTransportation->thing = gcnew Thing;
      XmlTextWriter^ writer = gcnew XmlTextWriter( filename,Encoding::UTF8 );
      writer->Formatting = Formatting::Indented;
      writer->WriteStartElement( "wrapper" );
      ser->Serialize( writer, myTransportation );
      writer->WriteEndElement();
      writer->Close();
   }
};

int main()
{
   Test^ t = gcnew Test;
   t->SerializeObject( "SoapElementOriginal.xml" );
   t->SerializeOverride( "SoapElementOverride.xml" );
   Console::WriteLine( "Finished writing two XML files." );
}
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;
public class Transportation
{
   // The SoapElementAttribute specifies that the
   // generated XML element name will be "Wheels"
   // instead of "Vehicle".
   [SoapElement("Wheels")]
   public string Vehicle;
   [SoapElement(DataType = "dateTime")]
   public DateTime CreationDate;
   [SoapElement(IsNullable = true)]
   public Thing thing;
}

public class Thing{
   [SoapElement(IsNullable=true)] public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("SoapElementOriginal.xml");
      t.SerializeOverride("SoapElementOverride.xml");
      Console.WriteLine("Finished writing two XML files.");
   }

   // Return an XmlSerializer used for overriding.
   public XmlSerializer CreateSoapOverrider()
   {
      // Create the SoapAttributes and SoapAttributeOverrides objects.
      SoapAttributes soapAttrs = new SoapAttributes();

      SoapAttributeOverrides soapOverrides =
      new SoapAttributeOverrides();

      /* Create an SoapElementAttribute to override
      the Vehicles property. */
      SoapElementAttribute soapElement1 =
      new SoapElementAttribute("Truck");
      // Set the SoapElement to the object.
      soapAttrs.SoapElement= soapElement1;

      /* Add the SoapAttributes to the SoapAttributeOverrides,
      specifying the member to override. */
      soapOverrides.Add(typeof(Transportation), "Vehicle", soapAttrs);

      // Create the XmlSerializer, and return it.
      XmlTypeMapping myTypeMapping = (new SoapReflectionImporter
      (soapOverrides)).ImportTypeMapping(typeof(Transportation));
      return new XmlSerializer(myTypeMapping);
   }

   public void SerializeOverride(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer ser = CreateSoapOverrider();

      // Create the object and serialize it.
      Transportation myTransportation =
      new Transportation();

      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate=DateTime.Now;
      myTransportation.thing = new Thing();

      XmlTextWriter writer =
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
   public void SerializeObject(string filename){
      // Create an XmlSerializer instance.
      XmlSerializer ser = new XmlSerializer(typeof(Transportation));
      Transportation myTransportation =
      new Transportation();
      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate = DateTime.Now;
      myTransportation.thing = new Thing();
      XmlTextWriter writer =
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
}
Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections
Imports System.Xml
Imports System.Text

Public Class Transportation
   ' The SoapElementAttribute specifies that the
   ' generated XML element name will be "Wheels"
   ' instead of "Vehicle".
   <SoapElement("Wheels")> Public Vehicle As String 
   <SoapElement(DataType:= "dateTime")> _
   public CreationDate As DateTime    
   <SoapElement(IsNullable:= true)> _
   public thing As Thing
End Class

Public Class Thing
   <SoapElement(IsNullable:=true)> public ThingName As string 
End Class

Public Class Test

   Shared Sub Main()
      Dim t As Test = New Test()
      t.SerializeObject("SoapElementOriginalVb.xml")
      t.SerializeOverride("SoapElementOverrideVb.xml")
      Console.WriteLine("Finished writing two XML files.")
   End Sub

   ' Return an XmlSerializer used for overriding.
   Public Function CreateSoapOverrider() As XmlSerializer 
      ' Create the SoapAttributes and SoapAttributeOverrides objects.
      Dim soapAttrs As SoapAttributes = New SoapAttributes()

      Dim soapOverrides As SoapAttributeOverrides = _
      New SoapAttributeOverrides()
            
      ' Create a SoapElementAttribute to override 
      ' the Vehicles property. 
      Dim soapElement1 As SoapElementAttribute = _
      New SoapElementAttribute("Truck")
      ' Set the SoapElement to the object.
      soapAttrs.SoapElement= soapElement1

      ' Add the SoapAttributes to the SoapAttributeOverrides,
      ' specifying the member to override. 
      soapOverrides.Add(GetType(Transportation), "Vehicle", soapAttrs)
      
      ' Create the XmlSerializer, and return it.
      Dim myTypeMapping As XmlTypeMapping = (New _
      SoapReflectionImporter (soapOverrides)).ImportTypeMapping _
      (GetType(Transportation))
      return New XmlSerializer(myTypeMapping)
   End Function

   Public Sub SerializeOverride(filename As String)
      ' Create an XmlSerializer instance.
      Dim ser As XmlSerializer = CreateSoapOverrider()

      ' Create the object and serialize it.
      Dim myTransportation As Transportation = _
      New Transportation()

      myTransportation.Vehicle = "MyCar"
      myTransportation.CreationDate = DateTime.Now
      myTransportation.thing= new Thing()
      
      Dim writer As XmlTextWriter = _
      New XmlTextWriter(filename, Encoding.UTF8)
      writer.Formatting = Formatting.Indented
      writer.WriteStartElement("wrapper")
      ser.Serialize(writer, myTransportation)
      writer.WriteEndElement()
      writer.Close()
   End Sub

   Public Sub SerializeObject(filename As String)
      ' Create an XmlSerializer instance.
      Dim ser As XmlSerializer = _
      New XmlSerializer(GetType(Transportation))
      
      Dim myTransportation As Transportation = _
      New Transportation()
      
      myTransportation.Vehicle = "MyCar"
      myTransportation.CreationDate=DateTime.Now
      myTransportation.thing= new Thing()

      Dim writer As XmlTextWriter = _
      new XmlTextWriter(filename, Encoding.UTF8)
      writer.Formatting = Formatting.Indented
      writer.WriteStartElement("wrapper")
      ser.Serialize(writer, myTransportation)
      writer.WriteEndElement()
      writer.Close()
   End Sub
End Class

설명

XmlTypeMapping 클래스 개체를 인코딩된 SOAP XML로 serialize 하는 데 사용 됩니다. 결과 XML은 World Wide Web 컨소시엄 문서 "SOAP(Simple Object Access Protocol) 1.1"의 섹션 5를 따릅니다. 만들기는 XmlTypeMapping 를 호출 하 여는 ImportTypeMapping 메서드를 SoapReflectionImporter 클래스입니다. 사용 된 XmlTypeMapping 의 인스턴스를 생성 하는 XmlSerializer 클래스. Serialization을 제어 하에 나열 된 특성 중 하나를 사용 는 인코딩된 SOAP Serialization을 제어 특성합니다.

속성

ElementName

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

매핑된 요소의 이름을 가져옵니다.

ElementName

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

매핑된 요소의 이름을 가져옵니다.

(다음에서 상속됨 XmlMapping)
Namespace

매핑된 개체의 XML 네임스페이스를 가져옵니다.

Namespace

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

매핑된 요소의 네임스페이스를 가져옵니다.

(다음에서 상속됨 XmlMapping)
TypeFullName

네임스페이스와 형식이 포함된 정규화된 형식 이름입니다.

TypeName

매핑된 개체의 형식 이름을 가져옵니다.

XsdElementName

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

매핑의 XSD 요소 이름을 가져옵니다.

(다음에서 상속됨 XmlMapping)
XsdTypeName

매핑된 개체의 XML 요소 이름을 가져옵니다.

XsdTypeNamespace

매핑된 개체의 XML 네임스페이스를 가져옵니다.

메서드

Equals(Object)

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

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

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

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

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

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

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

(다음에서 상속됨 Object)
SetKey(String)

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

매핑을 조회하는 데 사용되는 키를 설정합니다.

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보