XML:如何使用linq to xml解析下面的xml字符串?
<shift_details>
<shift_time>10:00 to 10:30</shift_time>
<count>0</count>
<shift_time>10:30 to 11:00</shift_time>
<count>0</count>
<shift_time>11:00 to 11:30</shift_time>
<count>0</count>
<shift_time>11:30 to 12:00</shift_time>
<count>0</count>
<shift_time>12:00 to 12:30</shift_time>
<count>0</count>
</shift_details>
代碼:
var slots = from c in xmlResponse.Descendants("shift_details")
select new TimeSlots
{
time = (string)c.Element("shift_time"),
count = (string)c.Element("count"),
};
上面的代碼返回只有一個插槽。但我的XML包含了太多的記錄項作爲輸出。
如何讀取上述xml中的所有記錄?
我相信你的意思是linq到xml – Jonesopolis
如果你控制XML的結構,我會改變XML,因爲它的結構不正確 –