我需要將對象序列化爲XML並返回。 XML已修復,我無法更改它。 bookingList
之後,我無法生成此結構。在序列化XML時更改元素的順序
我怎樣才能「團」這些<booking>
元素出現作爲一個列表,並保持<error>
& <counter>
名單<booking>
元素之前。
見我的例子在這裏:
結構,我需要....
<nicexml>
<key_id>1234567</key_id>
<surname>Jil</surname>
<name>Sander</name>
<station_id>1</station_id>
<ownBookings>
<bookingList>
<error></error>
<counter>20</counter>
<booking>
<bookingID>1234567890</bookingID>
</booking>
<booking>
<bookingID>2345678901</bookingID>
</booking>
</bookingList>
</ownBookings>
</nicexml>
結構我下面的C#代碼得到....
<nicexml>
<key_id>1234567</key_id>
<surname>Jil</surname>
<name>Sander</name>
<station_id>1</station_id>
<ownBookings>
<bookingList>
<booking>
<booking>
<bookingID>1234567890</bookingID>
</booking>
<booking>
<bookingID>2345678901</bookingID>
</booking>
<booking>
<error></error>
<counter>20</counter>
</bookingList>
</ownBookings>
</nicexml>
C#代碼:
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace xml_objects_serials
{
public class bookings
{
public class nicexml
{
public string key_id
{ get; set; }
public string surname
{ get; set; }
public string name
{ get; set; }
public int station_id
{ get; set; }
public ownBookings ownBookings
{ get; set; }
}
public class ownBookings
{
public bookingList bookingList
{ get; set; }
}
public class bookingList {
public string error
{ get; set; }
public int counter
{ get; set; }
public List<booking> booking= new List<booking>();
}
public class booking
{
public int bookingID
{ get; set; }
}
}
thx ...元素順序...爲什麼我沒有得到這從msdn ....謝謝你 –
我不知道這個「elementorder」。萬分感謝! –