웹 API를 사용하여 C# 목록으로 변환해야하는 xml 형식의 요청을 받고 있습니다. 여기 xml은 웹 API에서 변환을 나열합니다. #
내가 여기<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>
내가 요청 XML이 필요
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; }
}
}
는 변환 할 수있는 목록 개체에 대한
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# 클래스 내 C# 방법이다 받도록 요청 XML의 위의 클래스를 사용하여 목록에 추가합니다. 지금 경로에서 불법 오류가 발생했습니다. 모든 도움은 정말 감사하겠습니다. 디. 감사
업데이트 :
이
public static void ReadInventory()
{
XDocument doc = XDocument.Load(@"D:\\Sample\\Data2.xml");
XNamespace ns = doc.Root.Name.Namespace; // You will need to use this "ns" in every XPATH except attributes.
var v = from h in doc.Descendants(ns+"StatusApplicationControl")
select new StatusApplicationControl
{
Start = h.Attribute("Start").Value,
End = h.Attribute("End").Value
};
foreach (var item in v)
{
Console.Write("Start" + item.Start + " End " + item.End + "\r\n");
}
Console.WriteLine(v.Count());
}
는 난 단지 시작에 대한 이런 짓을했는지 ... 내가
<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>
"경로에 잘못된 경로가 잘못되었습니다"라는 메시지가 표시되면 먼저 경로를 확인해야합니다. 경로를 올바르게 확인할 수있게되면 LINQ to XML을 사용하여 XML 문자열에서 목록을 가져올 수 있습니다. – A3006
@ A3006 어떻게 그럴 수 있니? – Melvin
request.Content.ReadAsStreamAsync()에서 무엇을 얻고 있습니까? 지금 결과가 있습니까? – A3006