XmlElementAttribute.DataType Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
tarafından XmlSerializeroluşturulan XML öğesinin XML Şema tanımı (XSD) veri türünü alır veya ayarlar.
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
Özellik Değeri
XML Şeması veri türü.
Özel durumlar
Belirttiğiniz XML Şeması veri türü the.NET veri türüyle eşlenemez.
Örnekler
Aşağıdaki örnek, adlı bir alan içeren ve Group döndüren ArrayListadlı ExtraInfosınıfı serileştirir. Örnek, alanına öğesinin XmlElementAttribute iki örneğini uygular ve her örnek için farklı DataType değerler belirtir. Her örnek, XmlSerializer dizinine eklenen belirtilen türleri seri hale getirmesini sağlar.
using System;
using System.Collections;
using System.IO;
using System.Xml.Serialization;
public class Group
{
/* Apply two XmlElementAttributes to the field. Set the DataType
to string an int to allow the ArrayList to accept
both types. The Namespace is also set to different values
for each type. */
[XmlElement(DataType = "string",
Type = typeof(string),
Namespace = "http://www.cpandl.com"),
XmlElement(DataType = "int",
Namespace = "http://www.cohowinery.com",
Type = typeof(int))]
public ArrayList ExtraInfo;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeObject("ElementTypes.xml");
}
public void SerializeObject(string filename)
{
// A TextWriter is needed to write the file.
TextWriter writer = new StreamWriter(filename);
// Create the XmlSerializer using the XmlAttributeOverrides.
XmlSerializer s =
new XmlSerializer(typeof(Group));
// Create the object to serialize.
Group myGroup = new Group();
/* Add a string and an integer to the ArrayList returned
by the ExtraInfo field. */
myGroup.ExtraInfo = new ArrayList();
myGroup.ExtraInfo.Add("hello");
myGroup.ExtraInfo.Add(100);
// Serialize the object and close the TextWriter.
s.Serialize(writer,myGroup);
writer.Close();
}
}
Imports System.Collections
Imports System.IO
Imports System.Xml.Serialization
Public Class Group
' Apply two XmlElementAttributes to the field. Set the DataType
' to string and int to allow the ArrayList to accept
' both types. The Namespace is also set to different values
' for each type.
<XmlElement(DataType := "string", _
Type := GetType(String), _
Namespace := "http://www.cpandl.com"), _
XmlElement(DataType := "int", _
Type := GetType(Integer), _
Namespace := "http://www.cohowinery.com")> _
Public ExtraInfo As ArrayList
End Class
Public Class Run
Public Shared Sub Main()
Dim test As New Run()
test.SerializeObject("ElementTypes.xml")
End Sub
Public Sub SerializeObject(filename As String)
' A TextWriter is needed to write the file.
Dim writer As New StreamWriter(filename)
' Create the XmlSerializer using the XmlAttributeOverrides.
Dim s As New XmlSerializer(GetType(Group))
' Create the object to serialize.
Dim myGroup As New Group()
' Add a string and an integer to the ArrayList returned
' by the ExtraInfo field.
myGroup.ExtraInfo = New ArrayList()
myGroup.ExtraInfo.Add("hello")
myGroup.ExtraInfo.Add(100)
' Serialize the object and close the TextWriter.
s.Serialize(writer, myGroup)
writer.Close()
End Sub
End Class
Açıklamalar
Aşağıdaki tabloda, their.NET eşdeğerleri olan XML Şeması basit veri türleri listelenmiştir.
XML Şeması base64Binary ve hexBinary veri türleri için bir yapı dizisi Byte kullanın ve uygun şekilde "base64Binary" veya "hexBinary" olarak ayarlanmış bir XmlElementAttributeDataType uygulayın. XML Şeması time ve date veri türleri için türünü kullanın DateTime ve XmlElementAttribute "date" veya "time" olarak ayarlayın.DataType
Bir dizeye eşlenen her XML Şeması türü için, özelliğini XML Şema türüne ayarlanmış olarak uygulayın XmlElementAttributeDataType . Bunun yalnızca üyenin şemasını değil serileştirme biçimini de değiştirmesi mümkündür.
Uyarı
özelliği büyük/küçük harfe duyarlıdır, bu nedenle xml şeması veri türlerinden birine tam olarak ayarlamanız gerekir.
Uyarı
İkili verileri XML öğesi olarak geçirmek, xml şeması özniteliği olarak geçirmekten daha verimlidir.
XML veri türleri hakkında daha fazla bilgi için BKZ. XML Şeması Bölüm 2: Veri Türleri adlı World Wide Web Consortium belgesi.
| XSD veri tipi | .NET veri türü |
|---|---|
| Anyurı | String |
| base64Binary | Nesne dizisi Byte |
| Boolean | Boolean |
| byte | SByte |
| date | DateTime |
| tarih ve saat | DateTime |
| ondalık | Decimal |
| double | Double |
| VARLIK | String |
| VARLIK | String |
| yüzmek | Single |
| gDay | String |
| gMonth | String |
| gMonthDay | String |
| gYear | String |
| gYearMonth | String |
| Hexbinary | Nesne dizisi Byte |
| Kimlik | String |
| IDREF | String |
| IDREFS | String |
| int | Int32 |
| tamsayı | String |
| language | String |
| uzun | Int64 |
| İsim | String |
| Ncname | String |
| negativeInteger | String |
| NMTOKEN | String |
| NMTOKENS | String |
| normalizedString | String |
| nonNegativeInteger | String |
| nonPositiveInteger | String |
| GÖSTERİM | String |
| positiveInteger | String |
| QName | XmlQualifiedName |
| duration | String |
| String | String |
| short | Int16 |
| zaman | DateTime |
| token | String |
| işaretsiz bayt (unsignedByte) | Byte |
| işaretsiz tam sayı | UInt32 |
| işaretsiz uzun | UInt64 |
| işaretsizKısa | UInt16 |