Linq to XML遍历

 

 

XML实例文档
  1 XML文档 <?xml version="1.0" encoding="utf-8"?>
  2 <fenxiao_orders_get_response>
  3   <purchase_orders list="true">
  4     <purchase_order>
  5       <id>258429315086973</id>
  6       <buyer_payment>378.00</buyer_payment>
  7       <distributor_from>taobao</distributor_from>
  8       <distributor_username>小公主精品坊</distributor_username>
  9       <distributor_payment>347.36</distributor_payment>
 10       <receiver>
 11         <address>埤城镇菜市场大门向北50米 华硕联想专卖 XXXX)</address>
 12         <district>丹阳市</district>
 13         <city>镇江市</city>
 14         <name>XXX</name>
 15         <mobile_phone>158061014444</mobile_phone>
 16         <phone></phone>
 17         <zip>212311</zip>
 18         <state>江苏省</state>
 19       </receiver>
 20       <fenxiao_id>1321177225990</fenxiao_id>
 21       <created>2013-05-13 12:26:54</created>
 22       <modified>2013-05-13 12:27:23</modified>
 23       <memo></memo>
 24       <status>WAIT_SELLER_SEND_GOODS</status>
 25       <alipay_no>2013051300001000140005672268</alipay_no>
 26       <pay_time>2013-05-13 12:27:21</pay_time>
 27       <pay_type>ALIPAY_SURETY</pay_type>
 28       <post_fee>0.00</post_fee>
 29       <shipping>SELLER</shipping>
 30       <sub_purchase_orders list="true">
 31         <sub_purchase_order>
 32           <item_id>342150555073</item_id>
 33           <item_outer_id>SS32S5657Y-5</item_outer_id>
 34           <auction_price>501.00</auction_price>
 35           <sku_outer_id>02230</sku_outer_id>
 36           <sku_id>1626255255073</sku_id>
 37           <bill_fee>378.00</bill_fee>
 38           <num>1</num>
 39           <buyer_payment>378.00</buyer_payment>
 40           <distributor_payment>347.36</distributor_payment>
 41           <total_fee>347.36</total_fee>
 42           <fenxiao_id>1321177225990</fenxiao_id>
 43           <created>2013-05-13 12:26:54</created>
 44           <old_sku_properties>颜色分类:02黄色,尺码:36</old_sku_properties>
 45           <order_200_status>WAIT_SELLER_SEND_GOODS</order_200_status>
 46           <price>347.36</price>
 47           <refund_fee>0.00</refund_fee>
 48           <sc_item_id>0</sc_item_id>
 49           <sku_properties>颜色分类:02黄色,尺码:36</sku_properties>
 50           <snapshot_url>http://gongxiao.tmall.com/product/product_snapshot.htm?subOrderId=1321177225990</snapshot_url>
 51           <status>WAIT_SELLER_SEND_GOODS</status>
 52           <id>258429315086973</id>
 53           <tc_order_id>218773986530992</tc_order_id>
 54           <title>星期六2013新款夏款羊皮高跟撞色拼坡跟细带凉鞋女鞋子SS32S5657Y</title>
 55         </sub_purchase_order>
 56       </sub_purchase_orders>
 57       <supplier_flag>0</supplier_flag>
 58       <supplier_from>taobao</supplier_from>
 59       <supplier_memo></supplier_memo>
 60       <supplier_username>淘趣女鞋专营店</supplier_username>
 61       <tc_order_id>218773986530992</tc_order_id>
 62       <total_fee>347.36</total_fee>
 63       <trade_type>AGENT</trade_type>
 64     </purchase_order>
 65     <purchase_order>
 66       <id>345350203660933</id>
 67       <buyer_payment>465.00</buyer_payment>
 68       <distributor_from>taobao</distributor_from>
 69       <distributor_username>kuuki小铺</distributor_username>
 70       <distributor_payment>427.38</distributor_payment>
 71       <receiver>
 72         <address>清城南区2号楼1单元702</address>
 73         <district>大兴区</district>
 74         <city>北京市</city>
 75         <name>XXX</name>
 76         <mobile_phone>15901107928</mobile_phone>
 77         <phone></phone>
 78         <zip>102600</zip>
 79         <state>北京</state>
 80       </receiver>
 81       <fenxiao_id>1321068151888</fenxiao_id>
 82       <created>2013-05-13 11:59:53</created>
 83       <modified>2013-05-13 13:00:33</modified>
 84       <memo>分销商kuuki小铺(2013-05-13 13:00:33)(已付款,未发货) :发中通!。</memo>
 85       <order_messages list="true">
 86         <order_message>
 87           <message_title>分销商留言</message_title>
 88           <message_content>发中通!</message_content>
 89           <message_time>2013-05-13 13:00:33</message_time>
 90           <pic_url>null</pic_url>
 91         </order_message>
 92       </order_messages>
 93       <status>WAIT_SELLER_SEND_GOODS</status>
 94       <alipay_no>2013051300001000320005717495</alipay_no>
 95       <pay_time>2013-05-13 12:59:11</pay_time>
 96       <pay_type>ALIPAY_SURETY</pay_type>
 97       <post_fee>0.00</post_fee>
 98       <shipping>SELLER</shipping>
 99       <sub_purchase_orders list="true">
100         <sub_purchase_order>
101           <item_id>331727105073</item_id>
102           <item_outer_id>310045107-5</item_outer_id>
103           <auction_price>628.50</auction_price>
104           <sku_outer_id>0017225</sku_outer_id>
105           <sku_id>1554103375073</sku_id>
106           <bill_fee>465.00</bill_fee>
107           <num>1</num>
108           <buyer_payment>465.00</buyer_payment>
109           <distributor_payment>427.38</distributor_payment>
110           <total_fee>427.38</total_fee>
111           <fenxiao_id>1321068151289</fenxiao_id>
112           <created>2013-05-13 11:59:53</created>
113           <old_sku_properties>颜色分类:0017黑+金,尺码:35</old_sku_properties>
114           <order_200_status>WAIT_SELLER_SEND_GOODS</order_200_status>
115           <price>427.38</price>
116           <refund_fee>0.00</refund_fee>
117           <sc_item_id>0</sc_item_id>
118           <sku_properties>颜色分类:0017黑+金,尺码:35</sku_properties>
119           <snapshot_url>http://gongxiao.tmall.com/product/product_snapshot.htm?subOrderId=1321068151289</snapshot_url>
120           <status>WAIT_SELLER_SEND_GOODS</status>
121           <id>345350203660933</id>
122           <tc_order_id>258417910438629</tc_order_id>
123           <title>迪芙斯2013新品高跟牛皮撞色拼粗带金属凉鞋女鞋子5107-0017</title>
124         </sub_purchase_order>
125       </sub_purchase_orders>
126       <supplier_flag>0</supplier_flag>
127       <supplier_from>taobao</supplier_from>
128       <supplier_memo></supplier_memo>
129       <supplier_username>淘趣女鞋专营店</supplier_username>
130       <tc_order_id>258417910438629</tc_order_id>
131       <total_fee>427.38</total_fee>
132       <trade_type>AGENT</trade_type>
133     </purchase_order>
134       <total_results>47</total_results>
135 </fenxiao_orders_get_response>
136 <!--top164198.cm3-->

 

 1 string pp = xml.OuterXml;
 2             XElement xele = XElement.Parse(pp).Element("purchase_orders");
 3             XElement ll = XElement.Parse(pp);
 4 
 5            //查询出buyer_payment大于400的节点
 6             IEnumerable<XElement> order = from mmmm in xele.Elements("purchase_order") where Convert .ToDouble(mmmm.Element("buyer_payment").Value)>400 select mmmm;
 7 
 8             //或者IEnumerable<XElement> order = xele.Elements("purchase_order");
 9             foreach (XElement p in order)
10             {
11                 string aa = p.Element("buyer_payment").Value;
12                 IEnumerable<XElement> receiver = p.Elements("receiver");
13                 foreach (XElement a in receiver)
14                 {
15                     string address = a.Element("address").Value;
16                 }
17                 IEnumerable<XElement> sub_purchase_orders = p.Element("sub_purchase_orders").Elements("sub_purchase_order");
18                 foreach (XElement b in sub_purchase_orders)
19                 {
20                     string jkljk=b.Element("item_outer_id").Value;
21                 }
22             }
原文地址:https://www.cnblogs.com/xiaofengfeng/p/3075626.html