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,因为它的结构不正确 –