I am getting a request in the form of xml which i need converted to list in c# using web api.
Here's the request xml that i receive
<OTA_HotelInvCountNotifRQ xmlns="http://www.zzz.com/OTA/2015/03"
TimeStamp="2015-03-10T09:41:51.982" Version="1.2"> <Inventories
HotelCode="10001"> <Inventory> <StatusApplicationControl Start="2015-03-16"
End="2015-03-30" Mon="0" Tue="0" Wed="0" Thur="0" Fri="0" Sat="1" Sun="1"
InvTypeCode="DLX" AllInvCode="False" /> <InvCounts> <InvCount CountType="2"
Count="17" /> </InvCounts> </Inventory> <Inventory>
<StatusApplicationControl Start="2015-03-16" End="2015-03-30"
AllInvCode="False" Mon="1" Tue="1" Wed="1" Thur="1" Fri="1" Sat="1" Sun="1"
InvTypeCode="STD"></StatusApplicationControl> <InvCounts> <InvCount
CountType="2" Count="7" /> </InvCounts> </Inventory> </Inventories>
</OTA_HotelInvCountNotifRQ>
Here's my c# method
public HttpResponseMessage UpdateHotelAvailability(HttpRequestMessage request)
{
var doc = new XmlDocument();
doc.Load(request.Content.ReadAsStreamAsync().Result);
var serializer = new XmlSerializer(typeof(HRootObject));
using (var reader = XmlReader.Create(doc.InnerXml))
{
HRootObject Hobj = (HRootObject)serializer.Deserialize(reader);
}
HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.OK, 200);
return res;
}
c# class for the list object
public class sampleclass
{
public class StatusApplicationControl
{
public string Start { get; set; }
public string End { get; set; }
public string Mon { get; set; }
public string Tue { get; set; }
public string Wed { get; set; }
public string Thur { get; set; }
public string Fri { get; set; }
public string Sat { get; set; }
public string Sun { get; set; }
public string InvTypeCode { get; set; }
public string AllInvCode { get; set; }
}
public class InvCount
{
public string CountType { get; set; }
public string Count { get; set; }
}
public class InvCounts
{
public InvCount InvCount { get; set; }
}
public class Inventory
{
public StatusApplicationControl StatusApplicationControl { get; set; }
public InvCounts InvCounts { get; set; }
}
public class Inventories
{
public string HotelCode { get; set; }
public List<Inventory> Inventory { get; set; }
}
public class HRootObject
{
public string TimeStamp { get; set; }
public string Version { get; set; }
public Inventories Inventories { get; set; }
}
}
I need the request xml to be converted to a list by using the above class.I am getting illegal error in path now.Any help would be really appreciated. Thanks
Update :
This is what i get in the innerxml node of the doc
<OTA_HotelInvCountNotifRQ xmlns="http://www.zzz.com/OTA/2015/03"
TimeStamp="2015-03-10T09:41:51.982" Version="1.2"> <Inventories
HotelCode="10001"> <Inventory> <StatusApplicationControl Start="2015-03-16"
End="2015-03-30" Mon="0" Tue="0" Wed="0" Thur="0" Fri="0" Sat="1" Sun="1"
InvTypeCode="DLX" AllInvCode="False" /> <InvCounts> <InvCount CountType="2"
Count="17" /> </InvCounts> </Inventory> <Inventory>
<StatusApplicationControl Start="2015-03-16" End="2015-03-30"
AllInvCode="False" Mon="1" Tue="1" Wed="1" Thur="1" Fri="1" Sat="1" Sun="1"
InvTypeCode="STD"></StatusApplicationControl> <InvCounts> <InvCount
CountType="2" Count="7" /> </InvCounts> </Inventory> </Inventories>
</OTA_HotelInvCountNotifRQ>