我想反序列化一些看起来像这样的 XML:
XML:
<bookings>
<booking>
<timeStart>2012/7/2 11:00:00</timeStart>
<timeEnd>2012/7/2 12:00:00</timeEnd>
</booking>
<booking>
<timeStart>2012/7/10 08:30:00</timeStart>
<timeEnd>2012/7/10 10:30:00</timeEnd>
</booking>
</bookings>
我的代码:
var calUrlStr = "http://xxx.com?action=xxxxxx?x=1&y=2";
HttpWebRequest webRequest = GetWebRequest(calUrlStr);
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "bookings";
xRoot.IsNullable = true;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyDomain.GCalBooking.GCalBookings), xRoot);
Stream theStream = response.GetResponseStream();
StreamReader reader = new StreamReader(theStream);
MyDomain.GCalBooking.GCalBookings rateResponse = (MyDomain.GCalBooking.GCalBookings)xmlSerializer.Deserialize(reader);
我的课:
namespace MyDomain.GCalBooking
{
public class GCalBookings
{
public virtual List<Booking> Bookings { get; set; }
}
public class Booking
{
public string timeStart { get; set; }
public string timeEnd { get; set; }
}
}