SoapAttributeAttribute.DataType 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
XmlSerializer에 의해 생성된 SOAP 특성의 XSD(XML Schema Definition language) 데이터 형식을 가져오거나 설정합니다.
public:
property System::String ^ DataType { System::String ^ get(); void set(System::String ^ value); };
public string DataType { get; set; }
member this.DataType : string with get, set
Public Property DataType As String
속성 값
XML 스키마 데이터 형식입니다.
예외
지정한 XML 스키마 데이터 형식을 .NET 데이터 형식에 매핑할 수 없는 경우
예제
다음 예제에서는 가 적용되는 여러 필드가 포함된 클래스를 SoapAttributeAttribute serialize합니다. 속성은 DataType 및 필드에 대해 GroupNumber 설정됩니다 Today .
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
[SoapInclude(typeof(Vehicle))]
public class Group
{
[SoapAttribute (Namespace = "http://www.cpandl.com")]
public string GroupName;
[SoapAttribute(DataType = "base64Binary")]
public Byte [] GroupNumber;
[SoapAttribute(DataType = "date", AttributeName = "CreationDate")]
public DateTime Today;
[SoapElement(DataType = "nonNegativeInteger", ElementName = "PosInt")]
public string PostitiveInt;
public Vehicle GroupVehicle;
}
public class Vehicle
{
public string licenseNumber;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeObject("SoapAtts.xml");
test.DeserializeObject("SoapAtts.xml");
}
public void SerializeObject(string filename)
{
// Create an instance of the XmlSerializer class that
// can generate encoded SOAP messages.
XmlSerializer mySerializer = ReturnSOAPSerializer();
Group myGroup=MakeGroup();
// Writing the file requires a TextWriter.
XmlTextWriter writer =
new XmlTextWriter(filename, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("wrapper");
// Serialize the class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup);
writer.WriteEndElement();
writer.Close();
}
private Group MakeGroup(){
// 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(2002,5,2);
myGroup.Today = myDate;
myGroup.PostitiveInt= "10000";
myGroup.GroupVehicle = new Vehicle();
myGroup.GroupVehicle.licenseNumber="1234";
return myGroup;
}
public void DeserializeObject(string filename)
{
// Create an instance of the XmlSerializer class that
// can generate encoded SOAP messages.
XmlSerializer mySerializer = ReturnSOAPSerializer();
// Reading the file requires an XmlTextReader.
XmlTextReader reader=
new XmlTextReader(filename);
reader.ReadStartElement("wrapper");
// Deserialize and cast the object.
Group myGroup;
myGroup = (Group) mySerializer.Deserialize(reader);
reader.ReadEndElement();
reader.Close();
}
private XmlSerializer ReturnSOAPSerializer(){
// Create an instance of the XmlSerializer class.
XmlTypeMapping myMapping =
(new SoapReflectionImporter().ImportTypeMapping
(typeof(Group)));
return new XmlSerializer(myMapping);
}
}
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Xml.Schema
<SoapInclude(GetType(Vehicle))> _
Public Class Group
<SoapAttribute (Namespace:= "http:'www.cpandl.com")> _
Public GroupName As String
<SoapAttribute(DataType:= "base64Binary")> _
Public GroupNumber() As Byte
<SoapAttribute(DataType:= "date", AttributeName:= "CreationDate")> _
Public Today As DateTime
<SoapElement(DataType:= "nonNegativeInteger", _
ElementName:= "PosInt")> _
Public PostitiveInt As String
Public GroupVehicle As Vehicle
End Class
Public Class Vehicle
Public licenseNumber As String
End Class
Public Class Run
Shared Sub Main()
Dim test As Run = New Run()
test.SerializeObject("SoapAtts.xml")
test.DeserializeObject("SoapAtts.xml")
End Sub
Public Sub SerializeObject(filename As String)
' Create an instance of the XmlSerializer Class that
' can generate encoded SOAP messages.
Dim mySerializer As XmlSerializer = ReturnSOAPSerializer()
Dim myGroup As Group = MakeGroup()
' Writing the file requires a TextWriter.
Dim writer As XmlTextWriter = _
New XmlTextWriter(filename, Encoding.UTF8)
writer.Formatting = Formatting.Indented
writer.WriteStartElement("wrapper")
' Serialize the Class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup)
writer.WriteEndElement()
writer.Close()
End Sub
Private Function MakeGroup() As Group
' Create an instance of the Class that will be serialized.
Dim myGroup As Group = New Group()
' Set the object properties.
myGroup.GroupName = ".NET"
Dim hexByte() As Byte= New Byte(1){Convert.ToByte(100), _
Convert.ToByte(50)}
myGroup.GroupNumber = hexByte
Dim myDate As DateTime = New DateTime(2002,5,2)
myGroup.Today = myDate
myGroup.PostitiveInt= "10000"
myGroup.GroupVehicle = New Vehicle()
myGroup.GroupVehicle.licenseNumber="1234"
return myGroup
End Function
Public Sub DeserializeObject(filename As String)
' Create an instance of the XmlSerializer Class that
' can generate encoded SOAP messages.
Dim mySerializer As XmlSerializer = ReturnSOAPSerializer()
' Reading the file requires an XmlTextReader.
Dim reader As XmlTextReader = _
New XmlTextReader(filename)
reader.ReadStartElement("wrapper")
' Deserialize and cast the object.
Dim myGroup As Group
myGroup = _
CType(mySerializer.Deserialize(reader), Group)
reader.ReadEndElement()
reader.Close()
End Sub
private Function ReturnSOAPSerializer() As XmlSerializer
' Create an instance of the XmlSerializer Class.
Dim myMapping As XmlTypeMapping = _
(New SoapReflectionImporter().ImportTypeMapping _
(GetType(Group)))
return New XmlSerializer(myMapping)
End Function
End Class
설명
다음 표에서는 THEIR.NET 해당하는 XML 스키마 단순 데이터 형식을 나열합니다.
XML 스키마 base64Binary 및 hexBinary 데이터 형식의 경우 구조체 배열 Byte 을 사용하고 를 "base64Binary" 또는 "hexBinary"로 설정하여 적절하게 적용 SoapAttributeAttributeDataType 합니다. XML 스키마 time 및 date 데이터 형식의 경우 형식을 DateTime 사용하고 를 "date" 또는 "time"으로 DataType 설정하여 적용 SoapAttributeAttribute 합니다.
문자열에 매핑되는 모든 XML 스키마 데이터 형식에 대해 속성 DataType 이 설정된 를 XML 스키마 데이터 형식에 적용 SoapAttributeAttribute 합니다. 이렇게 하면 serialization 형식이 변경되지 않고 멤버에 대한 스키마만 변경됩니다.
참고
속성은 대/소문자를 구분하므로 정확히 XML 스키마 데이터 형식 중 하나로 설정해야 합니다.
참고
이진 데이터를 XML 요소로 전달하면 XML 특성으로 전달하는 것이 더 효율적입니다.
XML 스키마 데이터 형식에 대한 자세한 내용은 XML 스키마 2부: Datatypes](https://www.w3.org/TR/xmlschema-2/)라는 World Wide 컨소시엄 문서를 참조하세요.
| XSD 데이터 형식 | .NET 데이터 형식 |
|---|---|
| anyURI | String |
| base64Binary | Byte 개체의 배열 |
| boolean | Boolean |
| byte | SByte |
| 날짜 | DateTime |
| dateTime | DateTime |
| decimal | Decimal |
| double | Double |
| 엔터티 | String |
| 엔터티 | String |
| float | Single |
| gDay | String |
| gMonth | String |
| gMonthDay | String |
| gYear | String |
| gYearMonth | String |
| hexBinary | Byte 개체의 배열 |
| ID | String |
| IDREF | String |
| Idrefs | String |
| int | Int32 |
| 정수 | String |
| language | String |
| long | Int64 |
| Name | String |
| NCName | String |
| negativeInteger | String |
| NMTOKEN | String |
| NMTOKENS | String |
| normalizedString | String |
| nonNegativeInteger | String |
| nonPositiveInteger | String |
| NOTATION | String |
| positiveInteger | String |
| QName | XmlQualifiedName |
| duration | String |
| 문자열 | String |
| short | Int16 |
| time | DateTime |
| token | String |
| unsignedByte | Byte |
| unsignedInt | UInt32 |
| unsignedLong | UInt64 |
| unsignedShort | UInt16 |