是否可以將DataTable反序列化爲自定義類?一個SOAP請求的格式返回的DataTable使用XmlSerializer將DataTable反序列化爲自定義類
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="geolocation" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="geolocation">
<xs:complexType>
<xs:sequence>
<xs:element name="Latitude" type="xs:float" minOccurs="0"/>
<xs:element name="Longitude" type="xs:float" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<geolocation diffgr:id="geolocation" msdata:rowOrder="0">
<Latitude>48.8186</Latitude>
<Longitude>28.4681</Longitude>
</geolocation>
...
</NewDataSet>
</diffgr:diffgram>
我想它反序列化爲使用XmlSerializer的
XmlSerializer serializer = new XmlSerializer(typeof(Geolocation[]))
var Geolocations = (Geolocation)serializer.Deserialize(stream);
編輯的的
public class Geolocation {
public double latitude { get; set; }
public double longitude { get; set; }
}
陣列:我試圖做類似這個:
public class Geolocation {
[XmlElement("Latitude")]
public double Latitude { get; set; }
[XmlElement("Longitude")]
public double Longitude { get; set; }
}
但這不起作用
好吧,那麼你到目前爲止嘗試過什麼? – aevitas
@aevitas編輯 – Almis