0

我有以下格式的xml:

   <?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<draw><drawNo>381555</drawNo>
    <drawTime>2013-04-29T19:55:00+03:00</drawTime>
    <result>8</result>
    <result>10</result>
    <result>13</result>
    <result>15</result>
    <result>20</result>
    <result>21</result>
    <result>22</result>
    <result>25</result>
    <result>28</result>
    <result>29</result>
    <result>34</result>
    <result>36</result>
    <result>44</result>
    <result>46</result>
    <result>52</result>
    <result>62</result>
    <result>63</result>
    <result>72</result>
    <result>73</result>
    <result>75</result>
</draw>

我需要拆分数据...我尝试了以下代码:

XDocument loadeddata = XDocument.Parse(e.Result);
                var data = from query in loadeddata.Descendants("draw")
                           select new KinnoResults()
                                      {
                                          DrawNo = (String) query.Element("drawNo").Value,
                                          DrawTime = (String) query.Element("drawTime").Value,
                                          result1 = (String)query.Element("result").Value,
                                          result2 = (String)query.Element("result").Value

                                      };
                List<KinnoResults> list = data.ToList();

但是 result1 和 result2 具有相同的值 8。请问有什么想法吗?

4

2 回答 2

1

使用Elements,它会为您提供收藏

   select new KinnoResults()
   {
       DrawNo = (String)query.Elements("drawNo").Value,
       DrawTime = (String)query.Element("drawTime").Value,
       result1 = (String)query.Elements("result").ToList()[0].Value,
       result2 = (String)query.Elements("result").ToList()[1].Value

   };
于 2013-04-29T17:16:24.723 回答
1
var drawNo = loadeddata.Root.Element("drawNo").Value;
var drawTime = loadeddata.Root.Element("drawTime").Value;
var results = loadeddata.Descendants("result").Select(d => d.Value).ToList();
于 2013-04-29T17:23:02.553 回答