首先看到这个问题和Split XML Response 的接受答案,它适用于正常模式
但我的下一个要求是将Xml响应的重复节点拆分为DIctionary ..
我的XML回复
<Resp>
<status>00</status>
<errorcode>0</errorcode>
<errordescr>Success</errordescr>
- <data>
- <POS_STOREITEM>
<ITMSTRID_PK>1000116</ITMSTRID_PK>
<ITMID_FK>100101</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>52000</PRICE>
<STCKLMTCNT>45</STCKLMTCNT>
<SKUID>1420001</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>30/04/2015 10:04:13</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000115</ITMSTRID_PK>
<ITMID_FK>100100</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>1500</PRICE>
<STCKLMTCNT>13</STCKLMTCNT>
<SKUID>141000</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>30/04/2015 10:04:41</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000118</ITMSTRID_PK>
<ITMID_FK>100105</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>543</PRICE>
<STCKLMTCNT>1</STCKLMTCNT>
<SKUID>123333</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>05/05/2015 06:26:08</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000123</ITMSTRID_PK>
<ITMID_FK>100109</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>5454</PRICE>
<SKUID>565555</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>06/05/2015 09:11:06</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000112</ITMSTRID_PK>
<ITMID_FK>100097</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>2000</PRICE>
<STCKLMTCNT>3</STCKLMTCNT>
<SKUID>120002</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>08/05/2015 05:03:29</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000114</ITMSTRID_PK>
<ITMID_FK>100099</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>23321</PRICE>
<STCKLMTCNT>4</STCKLMTCNT>
<SKUID>32000</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>14/05/2015 07:57:23</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000107</ITMSTRID_PK>
<ITMID_FK>100095</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>7999.60</PRICE>
<STCKLMTCNT>5</STCKLMTCNT>
<SKUID>160002</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>14/05/2015 07:58:31</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000104</ITMSTRID_PK>
<ITMID_FK>100087</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>900000000.50</PRICE>
<STCKLMTCNT>1</STCKLMTCNT>
<SKUID>120001</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>15/05/2015 04:02:59</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000124</ITMSTRID_PK>
<ITMID_FK>100086</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>67867</PRICE>
<STCKLMTCNT>1</STCKLMTCNT>
<SKUID>34567678</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>15/05/2015 10:55:46</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000108</ITMSTRID_PK>
<ITMID_FK>100094</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>5000</PRICE>
<STCKLMTCNT>10</STCKLMTCNT>
<SKUID>160005</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>15/05/2015 11:37:08</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000125</ITMSTRID_PK>
<ITMID_FK>100126</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>40.90</PRICE>
<SKUID>909090</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>19/05/2015 09:45:04</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000121</ITMSTRID_PK>
<ITMID_FK>100107</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>2342324</PRICE>
<SKUID>234324234</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>20/05/2015 05:29:18</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000117</ITMSTRID_PK>
<ITMID_FK>100089</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>100</PRICE>
<STCKLMTCNT>122</STCKLMTCNT>
<SKUID>121212</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>20/05/2015 05:29:21</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_STOREITEM>
<ITMSTRID_PK>1000105</ITMSTRID_PK>
<ITMID_FK>100088</ITMID_FK>
<STRID_FK>10070</STRID_FK>
<PRICE>15200</PRICE>
<STCKLMTCNT>4</STCKLMTCNT>
<SKUID>121234</SKUID>
<STATUS>Y</STATUS>
<MODIFIEDDATE>20/05/2015 07:14:53</MODIFIEDDATE>
<DATAEXISTS>N</DATAEXISTS>
</POS_STOREITEM>
- <POS_ITEMTAX>
<TAXID_FK>10073</TAXID_FK>
<ITMSTRID_FK>1000108</ITMSTRID_FK>
<STATUS>Y</STATUS>
<DATAEXISTS>N</DATAEXISTS>
</POS_ITEMTAX>
- <POS_MAPDISCOUNT>
<DISID_FK>100223</DISID_FK>
<STRID_FK>10070</STRID_FK>
<DISPRODUCT>1000105</DISPRODUCT>
<DISTYPE>I</DISTYPE>
<DATAEXISTS>N</DATAEXISTS>
</POS_MAPDISCOUNT>
</data>
</Resp>
我尝试通过XELEMENT类进行序列化并获得每个节点的值......
- var SDvar = SDresponse.Descendants().First(node => node.Name ==
"status").Value.ToString();
但很难为多个重复节点序列化
如何将它们存储在字典中,因为它有多个具有相同名称的节点(POS_STOREITEM&gt; .. 存储在DICTIONATY中后我需要将它们存储在DB中,每个重复节点使用for循环。请帮助我...
答案 0 :(得分:1)
遍历每个POS_STOREITEM
元素并获取每个元素的字典?
foreach (var item in doc.Descendants("POS_STOREITEM")
{
var dictionary = item.Descendants()
.ToDictionary(e => e.Name.ToString(), e => e.Value);
// do something with dictionary
}
如果您发布的问题显示您尝试过的内容以及您遇到的问题,那将会很有帮助,因为这不是代码编写服务。我上面所做的并不是你已经得到的答案的巨大飞跃。