XML取值问题!最后一帖!

huayy 2011-10-19 03:49:28
XML结构

<?xml version="1.0" encoding="utf-8" ?><trades_sold_get_response><trades list="true"><trade><adjust_fee>内容</adjust_fee><buyer_nick>内容</buyer_nick><buyer_obtain_point_fee>内容</buyer_obtain_point_fee><buyer_rate>内容</buyer_rate><cod_fee>内容</cod_fee><cod_status>内容</cod_status><created>内容</created><discount_fee>内容</discount_fee><modified>内容</modified><num>内容</num><num_iid>内容</num_iid><orders list="true"><order><adjust_fee>内容</adjust_fee><buyer_rate>内容</buyer_rate><discount_fee>内容</discount_fee><num>内容</num><num_iid>内容</num_iid><oid>内容</oid><outer_iid>内容</outer_iid><outer_sku_id>内容</outer_sku_id><payment>内容</payment><pic_path>内容</pic_path><price>内容</price><refund_status>内容</refund_status><seller_rate>内容</seller_rate><seller_type>内容</seller_type><sku_id>内容</sku_id><sku_properties_name>内容</sku_properties_name><status>内容</status><title>内容</title><total_fee>内容</total_fee></order></orders><payment>内容</payment><pic_path>内容</pic_path><point_fee>内容</point_fee><post_fee>内容</post_fee><price>内容</price><real_point_fee>内容</real_point_fee><received_payment>内容</received_payment><receiver_address>内容</receiver_address><receiver_city>内容</receiver_city><receiver_district>内容</receiver_district><receiver_mobile>内容</receiver_mobile><receiver_name>内容</receiver_name><receiver_phone></receiver_phone><receiver_state>内容</receiver_state><receiver_zip>内容</receiver_zip><seller_nick>内容</seller_nick><seller_rate>内容</seller_rate><shipping_type>内容</shipping_type><sid>内容</sid><status>内容</status><tid>内容</tid><title>内容</title><total_fee>内容</total_fee><type>内容</type></trade><trade><adjust_fee>内容</adjust_fee><buyer_nick>内容</buyer_nick><buyer_obtain_point_fee>内容</buyer_obtain_point_fee><buyer_rate>内容</buyer_rate><cod_fee>内容</cod_fee><cod_status>内容</cod_status><created>内容</created><discount_fee>内容</discount_fee><modified>内容</modified><orders list="true"><order><adjust_fee>内容</adjust_fee><buyer_rate>内容</buyer_rate><discount_fee>内容</discount_fee><num>内容</num><num_iid>内容</num_iid><oid>内容</oid><outer_iid>内容</outer_iid><payment>内容</payment><pic_path>内容</pic_path><price>内容</price><refund_status>内容</refund_status><seller_rate>内容</seller_rate><seller_type>内容</seller_type><sku_id>内容</sku_id><sku_properties_name>内容</sku_properties_name><status>内容</status><title>内容</title><total_fee>内容</total_fee></order><order><adjust_fee>内容</adjust_fee><buyer_rate>内容</buyer_rate><discount_fee>内容</discount_fee><num>内容</num><num_iid>内容</num_iid><oid>内容</oid><outer_iid>内容</outer_iid><payment>内容</payment><pic_path>内容</pic_path><price>内容</price><refund_status>内容</refund_status><seller_rate>内容</seller_rate><seller_type>内容</seller_type><sku_id>内容</sku_id><sku_properties_name>内容</sku_properties_name><status>内容</status><title>内容</title><total_fee>内容</total_fee></order><order><adjust_fee>内容</adjust_fee><buyer_rate>内容</buyer_rate><discount_fee>内容</discount_fee><num>内容</num><num_iid>内容</num_iid><oid>内容</oid><outer_iid>内容</outer_iid><payment>内容</payment><pic_path>内容</pic_path><price>内容</price><refund_status>内容</refund_status><seller_rate>内容</seller_rate><seller_type>内容</seller_type><sku_id>内容</sku_id><sku_properties_name>内容</sku_properties_name><status>内容</status><title>内容</title><total_fee>内容</total_fee></order></orders><payment>内容</payment><point_fee>内容</point_fee><post_fee>内容</post_fee><real_point_fee>内容</real_point_fee><received_payment>内容</received_payment><receiver_address>内容</receiver_address><receiver_city>内容</receiver_city><receiver_district>内容</receiver_district><receiver_mobile>内容</receiver_mobile><receiver_name>内容</receiver_name><receiver_phone></receiver_phone><receiver_state>内容</receiver_state><receiver_zip>内容</receiver_zip><seller_nick>内容</seller_nick><seller_rate>内容</seller_rate><shipping_type>内容</shipping_type><sid>内容</sid><status>内容</status><tid>内容</tid><title>内容</title><total_fee>内容</total_fee><type>内容</type></trade></trades><total_results>内容</total_results></trades_sold_get_response><!--top016071.cm4-->



需要提取trade节点下的adjust_fee等字段内容存入 ms sqlserver表1;
同时需要提取order节点下的adjust_fee等字段内容存入表2;最重要的是,在存入表2的时候,还需要将trade节点下的tid节点的内容也存入表2某列(tid的内容是唯一的)。

我目前所使用的代码:



Dim xmldoc As New XmlDocument()
xmldoc.Load(Server.MapPath("XML/1.xml"))
Dim nodelist As XmlNodeList = xmldoc.SelectNodes("//trades_sold_get_response/trades/trade") '指向XML所在节点

For Each nl As XmlNode In nodelist


Dim tid = nl.Item("tid").InnerText '目前取tid的值是正常的


Dim nodelist_car As XmlNodeList = xmldoc.SelectNodes("//trades_sold_get_response/trades/trade/orders/order") '指向购物车内容所在节点
For Each nl_car As XmlNode In nodelist_car

Dim oid = nl_car.Item("oid").InnerText '取oid的值也是正常的

'我想在这个循环里取到tid的值,我估计是我的写法不对,可能对for each的理解就有问题。求代码!
Next

Next





因为我对xml结构、语法、方法等都甚不熟悉,请各位大大指教!谢谢膜拜!
...全文
245 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
huayy 2011-10-20
  • 打赏
  • 举报
回复
问题已经在http://topic.csdn.net/u/20111019/19/038db66a-3227-4804-8384-021d1d122e14.html解决了

谢谢各位的帮助!
风骑士之怒 2011-10-20
  • 打赏
  • 举报
回复

static void Main(string[] args)
{
XElement root = XElement.Load("F:\\a.xml");

IEnumerable<XElement> q = root.Element("trades").Elements("trade");

foreach (XElement row in q)
{
string tid = row.Element("tid").Value;
Console.WriteLine();
Console.WriteLine("tid为{0}的trade:", tid);
Console.WriteLine();
foreach (XElement column in row.Elements())
{
if (column.Name != "orders")
{
Console.WriteLine("字段名:{0} - 字段值:{1}", column.Name, column.Value);
}
else
{
foreach (XElement subRow in column.Elements())
{
string oid = subRow.Element("oid").Value;
Console.WriteLine();
Console.WriteLine(" tid为{0} oid为{1}的order:", tid, oid);
Console.WriteLine();
Console.WriteLine(" 字段名:tid - 字段值:{0}", tid);
foreach (XElement subColumn in subRow.Elements())
{
Console.WriteLine(" 字段名:{0} - 字段值:{1}", subColumn.Name, subColumn.Value);
}
}
}
}
}
Console.Read();
}


按照你的XML

第一个trade里面有一条order
第二个trade里面有三条order

那表2里面的tid列,应该是

第一个tid
第二个tid
第二个tid
第二个tid

对的吧?
ailin84 2011-10-20
  • 打赏
  • 举报
回复

<?xml version="1.0" encoding="utf-8" ?>
<trades_sold_get_response>
<trades list="true">
<trade>
<adjust_fee>0.00</adjust_fee>
<buyer_nick>name1</buyer_nick>
<buyer_obtain_point_fee>0</buyer_obtain_point_fee>
<buyer_rate>false</buyer_rate>
<cod_fee>0.00</cod_fee>
<cod_status>NEW_CREATED</cod_status>
<created>2011-10-18 18:51:51</created>
<discount_fee>0.00</discount_fee>
<modified>2011-10-18 18:51:51</modified>
<num>1</num>
<num_iid>12802062045</num_iid>
<orders list="true">
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12802062045</num_iid>
<oid>105514470449621</oid>
<outer_iid>12447</outer_iid>
<outer_sku_id>12447</outer_sku_id>
<payment>158.00</payment>
<pic_path>http://img04.taobaocdn.com//i4/T1JqGqXXxKXXaNKVw0_034131.jpg</pic_path>
<price>158.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>15672873456</sku_id>
<sku_properties_name>颜色:黑色;尺码:M</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>2011新品黑色</title>
<total_fee>158.00</total_fee>
</order>
</orders>
<payment>158.00</payment>
<pic_path>http://img04.taobaocdn.com/xx.jpg</pic_path>
<point_fee>0</point_fee>
<post_fee>0.00</post_fee>
<price>158.00</price>
<real_point_fee>0</real_point_fee>
<received_payment>0.00</received_payment>
<receiver_address>金沙江路5号90</receiver_address>
<receiver_city>上海市</receiver_city>
<receiver_district>普陀区</receiver_district>
<receiver_mobile>10001940859</receiver_mobile>
<receiver_name>程敏</receiver_name>
<receiver_phone></receiver_phone>
<receiver_state>上海</receiver_state>
<receiver_zip>200333</receiver_zip>
<seller_nick>旗舰店</seller_nick>
<seller_rate>false</seller_rate>
<shipping_type>free</shipping_type>
<sid>105514470449621</sid>
<status>WAIT_BUYER_PAY</status>
<tid>105514470449621</tid>
<title>旗舰店</title>
<total_fee>158.00</total_fee>
<type>fixed</type>
</trade>
<trade>
<adjust_fee>0.00</adjust_fee>
<buyer_nick>hitoli1</buyer_nick>
<buyer_obtain_point_fee>0</buyer_obtain_point_fee>
<buyer_rate>false</buyer_rate>
<cod_fee>0.00</cod_fee>
<cod_status>NEW_CREATED</cod_status>
<created>2011-10-17 17:48:01</created>
<discount_fee>0.00</discount_fee>
<modified>2011-10-17 17:48:02</modified>
<orders list="true">
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12902270495</num_iid>
<oid>103971730900011</oid>
<outer_iid>13292/13293</outer_iid>
<payment>146.00</payment>
<pic_path>http://img02.taobaocdn.com/.jpg</pic_path>
<price>146.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>17680284471</sku_id>
<sku_properties_name>颜色分类:男84006;尺码:M</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>84006/74006</title>
<total_fee>146.00</total_fee>
</order>
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12902270495</num_iid>
<oid>103971730910011</oid>
<outer_iid>13292/13293</outer_iid>
<payment>146.00</payment>
<pic_path>http://img02.taobaocd.com/bao.jpg</pic_path>
<price>146.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>17680284476</sku_id>
<sku_properties_name>颜色分类:女74006;尺码:XXL</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>84006/74006</title>
<total_fee>146.00</total_fee>
</order>
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12902270495</num_iid>
<oid>103971730920011</oid>
<outer_iid>13292/13293</outer_iid>
<payment>146.00</payment>
<pic_path>http://img02.taobaocdn.com//i2.jpg</pic_path>
<price>146.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>17680284473</sku_id>
<sku_properties_name>颜色分类:女74006;尺码:XL</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>84006/74006</title>
<total_fee>146.00</total_fee>
</order>
</orders>
<payment>438.00</payment>
<point_fee>0</point_fee>
<post_fee>0.00</post_fee>
<real_point_fee>0</real_point_fee>
<received_payment>0.00</received_payment>
<receiver_address>上海市曹杨七村120</receiver_address>
<receiver_city>上海市</receiver_city>
<receiver_district>普陀区</receiver_district>
<receiver_mobile>10016522698</receiver_mobile>
<receiver_name>郑龙</receiver_name>
<receiver_phone></receiver_phone>
<receiver_state>上海</receiver_state>
<receiver_zip>200062</receiver_zip>
<seller_nick>旗舰店</seller_nick>
<seller_rate>false</seller_rate>
<shipping_type>free</shipping_type>
<sid>103971730890011</sid>
<status>WAIT_BUYER_PAY</status>
<tid>103971730890011</tid>
<title>旗舰店</title>
<total_fee>438.00</total_fee>
<type>fixed</type>
</trade>
</trades>
<total_results>4</total_results>
</trades_sold_get_response>
<!--top202084.cm3-->


在VS里 按着Ctrl 按K再按D 就自动给你格式化了

xml文件取值的问题,用很多方式可以的啊,linq xpath xquery


XmlDocument doc = new XmlDocument();
doc.LoadXml("xml内容");
var list = doc.DocumentElement.SelectNodes("trades/trade");
foreach (XmlNode item in list)
{
string tid = item.SelectSingleNode("tid").FirstChild.Value;
string trade_adjust_fee = item.SelectSingleNode("adjust_fee").FirstChild.Value;

//插入数据
string tab1Sql = "insert into 表1 (adjust_fee) values (@trade_adjust_fee)";
//...
var orders = item.SelectNodes("order");
foreach (XmlNode node in orders)
{
string order_adjust_fee = item.SelectSingleNode("adjust_fee").FirstChild.Value;
//插入数据
string sql = "insert into 表2 (adjust_fee,tid) values (@order_adjust_fee,@tid)";
//......
}
}

ailin84 2011-10-20
  • 打赏
  • 举报
回复

<?xml version="1.0" encoding="utf-8" ?>
<trades_sold_get_response>
<trades list="true">
<trade>
<adjust_fee>0.00</adjust_fee>
<buyer_nick>name1</buyer_nick>
<buyer_obtain_point_fee>0</buyer_obtain_point_fee>
<buyer_rate>false</buyer_rate>
<cod_fee>0.00</cod_fee>
<cod_status>NEW_CREATED</cod_status>
<created>2011-10-18 18:51:51</created>
<discount_fee>0.00</discount_fee>
<modified>2011-10-18 18:51:51</modified>
<num>1</num>
<num_iid>12802062045</num_iid>
<orders list="true">
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12802062045</num_iid>
<oid>105514470449621</oid>
<outer_iid>12447</outer_iid>
<outer_sku_id>12447</outer_sku_id>
<payment>158.00</payment>
<pic_path>http://img04.taobaocdn.com//i4/T1JqGqXXxKXXaNKVw0_034131.jpg</pic_path>
<price>158.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>15672873456</sku_id>
<sku_properties_name>颜色:黑色;尺码:M</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>2011新品黑色</title>
<total_fee>158.00</total_fee>
</order>
</orders>
<payment>158.00</payment>
<pic_path>http://img04.taobaocdn.com/xx.jpg</pic_path>
<point_fee>0</point_fee>
<post_fee>0.00</post_fee>
<price>158.00</price>
<real_point_fee>0</real_point_fee>
<received_payment>0.00</received_payment>
<receiver_address>金沙江路5号90</receiver_address>
<receiver_city>上海市</receiver_city>
<receiver_district>普陀区</receiver_district>
<receiver_mobile>10001940859</receiver_mobile>
<receiver_name>程敏</receiver_name>
<receiver_phone></receiver_phone>
<receiver_state>上海</receiver_state>
<receiver_zip>200333</receiver_zip>
<seller_nick>旗舰店</seller_nick>
<seller_rate>false</seller_rate>
<shipping_type>free</shipping_type>
<sid>105514470449621</sid>
<status>WAIT_BUYER_PAY</status>
<tid>105514470449621</tid>
<title>旗舰店</title>
<total_fee>158.00</total_fee>
<type>fixed</type>
</trade>
<trade>
<adjust_fee>0.00</adjust_fee>
<buyer_nick>hitoli1</buyer_nick>
<buyer_obtain_point_fee>0</buyer_obtain_point_fee>
<buyer_rate>false</buyer_rate>
<cod_fee>0.00</cod_fee>
<cod_status>NEW_CREATED</cod_status>
<created>2011-10-17 17:48:01</created>
<discount_fee>0.00</discount_fee>
<modified>2011-10-17 17:48:02</modified>
<orders list="true">
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12902270495</num_iid>
<oid>103971730900011</oid>
<outer_iid>13292/13293</outer_iid>
<payment>146.00</payment>
<pic_path>http://img02.taobaocdn.com/.jpg</pic_path>
<price>146.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>17680284471</sku_id>
<sku_properties_name>颜色分类:男84006;尺码:M</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>84006/74006</title>
<total_fee>146.00</total_fee>
</order>
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12902270495</num_iid>
<oid>103971730910011</oid>
<outer_iid>13292/13293</outer_iid>
<payment>146.00</payment>
<pic_path>http://img02.taobaocd.com/bao.jpg</pic_path>
<price>146.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>17680284476</sku_id>
<sku_properties_name>颜色分类:女74006;尺码:XXL</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>84006/74006</title>
<total_fee>146.00</total_fee>
</order>
<order>
<adjust_fee>0.00</adjust_fee>
<buyer_rate>false</buyer_rate>
<discount_fee>0.00</discount_fee>
<num>1</num>
<num_iid>12902270495</num_iid>
<oid>103971730920011</oid>
<outer_iid>13292/13293</outer_iid>
<payment>146.00</payment>
<pic_path>http://img02.taobaocdn.com//i2.jpg</pic_path>
<price>146.00</price>
<refund_status>NO_REFUND</refund_status>
<seller_rate>false</seller_rate>
<seller_type>B</seller_type>
<sku_id>17680284473</sku_id>
<sku_properties_name>颜色分类:女74006;尺码:XL</sku_properties_name>
<status>WAIT_BUYER_PAY</status>
<title>84006/74006</title>
<total_fee>146.00</total_fee>
</order>
</orders>
<payment>438.00</payment>
<point_fee>0</point_fee>
<post_fee>0.00</post_fee>
<real_point_fee>0</real_point_fee>
<received_payment>0.00</received_payment>
<receiver_address>上海市曹杨七村120</receiver_address>
<receiver_city>上海市</receiver_city>
<receiver_district>普陀区</receiver_district>
<receiver_mobile>10016522698</receiver_mobile>
<receiver_name>郑龙</receiver_name>
<receiver_phone></receiver_phone>
<receiver_state>上海</receiver_state>
<receiver_zip>200062</receiver_zip>
<seller_nick>旗舰店</seller_nick>
<seller_rate>false</seller_rate>
<shipping_type>free</shipping_type>
<sid>103971730890011</sid>
<status>WAIT_BUYER_PAY</status>
<tid>103971730890011</tid>
<title>旗舰店</title>
<total_fee>438.00</total_fee>
<type>fixed</type>
</trade>
</trades>
<total_results>4</total_results>
</trades_sold_get_response>
<!--top202084.cm3-->


在VS里 按着Ctrl 按K再按D 就自动给你格式化了

xml文件取值的问题,用很多方式可以的啊,linq xpath xquery


XmlDocument doc = new XmlDocument();
doc.LoadXml("xml内容");
var list = doc.DocumentElement.SelectNodes("trades/trade");
foreach (XmlNode item in list)
{
string tid = item.SelectSingleNode("tid").FirstChild.Value;
string trade_adjust_fee = item.SelectSingleNode("adjust_fee").FirstChild.Value;

//插入数据
string tab1Sql = "insert into 表1 (adjust_fee) values (@trade_adjust_fee)";
//...
var orders = item.SelectNodes("order");
foreach (XmlNode node in orders)
{
string order_adjust_fee = item.SelectSingleNode("adjust_fee").FirstChild.Value;
//插入数据
string sql = "insert into 表2 (adjust_fee,tid) values (@order_adjust_fee,@tid)";
//......
}
}

风骑士之怒 2011-10-20
  • 打赏
  • 举报
回复
我看看
huayy 2011-10-19
  • 打赏
  • 举报
回复

<?xml version="1.0" encoding="utf-8" ?><trades_sold_get_response><trades list="true"><trade><adjust_fee>0.00</adjust_fee><buyer_nick>name1</buyer_nick><buyer_obtain_point_fee>0</buyer_obtain_point_fee><buyer_rate>false</buyer_rate><cod_fee>0.00</cod_fee><cod_status>NEW_CREATED</cod_status><created>2011-10-18 18:51:51</created><discount_fee>0.00</discount_fee><modified>2011-10-18 18:51:51</modified><num>1</num><num_iid>12802062045</num_iid><orders list="true"><order><adjust_fee>0.00</adjust_fee><buyer_rate>false</buyer_rate><discount_fee>0.00</discount_fee><num>1</num><num_iid>12802062045</num_iid><oid>105514470449621</oid><outer_iid>12447</outer_iid><outer_sku_id>12447</outer_sku_id><payment>158.00</payment><pic_path>http://img04.taobaocdn.com//i4/T1JqGqXXxKXXaNKVw0_034131.jpg</pic_path><price>158.00</price><refund_status>NO_REFUND</refund_status><seller_rate>false</seller_rate><seller_type>B</seller_type><sku_id>15672873456</sku_id><sku_properties_name>颜色:黑色;尺码:M</sku_properties_name><status>WAIT_BUYER_PAY</status><title>2011新品黑色</title><total_fee>158.00</total_fee></order></orders><payment>158.00</payment><pic_path>http://img04.taobaocdn.com/xx.jpg</pic_path><point_fee>0</point_fee><post_fee>0.00</post_fee><price>158.00</price><real_point_fee>0</real_point_fee><received_payment>0.00</received_payment><receiver_address>金沙江路5号90</receiver_address><receiver_city>上海市</receiver_city><receiver_district>普陀区</receiver_district><receiver_mobile>10001940859</receiver_mobile><receiver_name>程敏</receiver_name><receiver_phone></receiver_phone><receiver_state>上海</receiver_state><receiver_zip>200333</receiver_zip><seller_nick>旗舰店</seller_nick><seller_rate>false</seller_rate><shipping_type>free</shipping_type><sid>105514470449621</sid><status>WAIT_BUYER_PAY</status><tid>105514470449621</tid><title>旗舰店</title><total_fee>158.00</total_fee><type>fixed</type></trade><trade><adjust_fee>0.00</adjust_fee><buyer_nick>hitoli1</buyer_nick><buyer_obtain_point_fee>0</buyer_obtain_point_fee><buyer_rate>false</buyer_rate><cod_fee>0.00</cod_fee><cod_status>NEW_CREATED</cod_status><created>2011-10-17 17:48:01</created><discount_fee>0.00</discount_fee><modified>2011-10-17 17:48:02</modified><orders list="true"><order><adjust_fee>0.00</adjust_fee><buyer_rate>false</buyer_rate><discount_fee>0.00</discount_fee><num>1</num><num_iid>12902270495</num_iid><oid>103971730900011</oid><outer_iid>13292/13293</outer_iid><payment>146.00</payment><pic_path>http://img02.taobaocdn.com/.jpg</pic_path><price>146.00</price><refund_status>NO_REFUND</refund_status><seller_rate>false</seller_rate><seller_type>B</seller_type><sku_id>17680284471</sku_id><sku_properties_name>颜色分类:男84006;尺码:M</sku_properties_name><status>WAIT_BUYER_PAY</status><title>84006/74006</title><total_fee>146.00</total_fee></order><order><adjust_fee>0.00</adjust_fee><buyer_rate>false</buyer_rate><discount_fee>0.00</discount_fee><num>1</num><num_iid>12902270495</num_iid><oid>103971730910011</oid><outer_iid>13292/13293</outer_iid><payment>146.00</payment><pic_path>http://img02.taobaocd.com/bao.jpg</pic_path><price>146.00</price><refund_status>NO_REFUND</refund_status><seller_rate>false</seller_rate><seller_type>B</seller_type><sku_id>17680284476</sku_id><sku_properties_name>颜色分类:女74006;尺码:XXL</sku_properties_name><status>WAIT_BUYER_PAY</status><title>84006/74006</title><total_fee>146.00</total_fee></order><order><adjust_fee>0.00</adjust_fee><buyer_rate>false</buyer_rate><discount_fee>0.00</discount_fee><num>1</num><num_iid>12902270495</num_iid><oid>103971730920011</oid><outer_iid>13292/13293</outer_iid><payment>146.00</payment><pic_path>http://img02.taobaocdn.com//i2.jpg</pic_path><price>146.00</price><refund_status>NO_REFUND</refund_status><seller_rate>false</seller_rate><seller_type>B</seller_type><sku_id>17680284473</sku_id><sku_properties_name>颜色分类:女74006;尺码:XL</sku_properties_name><status>WAIT_BUYER_PAY</status><title>84006/74006</title><total_fee>146.00</total_fee></order></orders><payment>438.00</payment><point_fee>0</point_fee><post_fee>0.00</post_fee><real_point_fee>0</real_point_fee><received_payment>0.00</received_payment><receiver_address>上海市曹杨七村120</receiver_address><receiver_city>上海市</receiver_city><receiver_district>普陀区</receiver_district><receiver_mobile>10016522698</receiver_mobile><receiver_name>郑龙</receiver_name><receiver_phone></receiver_phone><receiver_state>上海</receiver_state><receiver_zip>200062</receiver_zip><seller_nick>旗舰店</seller_nick><seller_rate>false</seller_rate><shipping_type>free</shipping_type><sid>103971730890011</sid><status>WAIT_BUYER_PAY</status><tid>103971730890011</tid><title>旗舰店</title><total_fee>438.00</total_fee><type>fixed</type></trade></trades><total_results>4</total_results></trades_sold_get_response><!--top202084.cm3-->



这是XML文件的内容



Dim xmldoc As New XmlDocument()
xmldoc.Load(Server.MapPath("XML/1.xml"))
Dim nodelist As XmlNodeList = xmldoc.SelectNodes("//trades_sold_get_response/trades/trade") '指向XML所在节点

For Each nl As XmlNode In nodelist


Dim tid = nl.Item("tid").InnerText '目前取tid的值是正常的


Dim nodelist_car As XmlNodeList = xmldoc.SelectNodes("//trades_sold_get_response/trades/trade/orders/order") '指向购物车内容所在节点
For Each nl_car As XmlNode In nodelist_car

Dim oid = nl_car.Item("oid").InnerText '取oid的值也是正常的

'我想在这个循环里取到tid的值,我估计是我的写法不对,可能对for each的理解就有问题。求代码!
'这里的tid会是重复的
Next

Next




huayy 2011-10-19
  • 打赏
  • 举报
回复
好的 稍等,我把XML文件和导出表的内容马上帖出来。
wang_pei_1984 2011-10-19
  • 打赏
  • 举报
回复
还没有听明白你的意思,
你最好是把XML文件写出来,导出来的表内容也贴出来,我才知道你想要的是什么
huayy 2011-10-19
  • 打赏
  • 举报
回复
在后面取tid会是重复的,导致都是第一个<tid></tid>节点的值
可能出现这样的值

1111
1111
1111
2222
2222
2222
3333
3333
3333
4444
4444
4444

而我想要得到的值是
1111
2222
3333
4444

如果两次嵌套循环的次数只有四次的话
得到的数据会是
1111
1111
1111
2222
wang_pei_1984 2011-10-19
  • 打赏
  • 举报
回复
 Dim xmldoc As XmlDocument = New XmlDocument()
xmldoc.Load(Server.MapPath("test.xml"))
Dim nodelist As XmlNodeList = xmldoc.SelectNodes("trades_sold_get_response/trades/trade") '指向XML所在节点

For Each nl As XmlNode In nodelist


Dim tid = nl.Item("tid").InnerText '目前取tid的值是正常的


Dim nodelist_car As XmlNodeList = xmldoc.SelectNodes("//trades_sold_get_response/trades/trade/orders/order") '指向购物车内容所在节点
For Each nl_car As XmlNode In nodelist_car

Dim oid = nl_car.Item("oid").InnerText '取oid的值也是正常的

'我想在这个循环里取到tid的值,我估计是我的写法不对,可能对for each的理解就有问题。求代码!

'你不是取到tid了吗?
Next

Next
wang_pei_1984 2011-10-19
  • 打赏
  • 举报
回复
xmldoc.Load(Server.MapPath("XML/1.xml"))
Dim nodelist As XmlNodeList = xmldoc.SelectNodes("//trades_sold_get_response/trades/trade") '指向XML所在节点

For Each nl As XmlNode In nodelist


Dim tid = nl.Item("tid").InnerText '目前取tid的值是正常的

Dim nodelist_car As XmlNodeList = xmldoc.SelectNodes("//trades_sold_get_response/trades/trade/orders/order") '指向购物车内容所在节点
For Each nl_car As XmlNode In nodelist_car

Dim oid = nl_car.Item("oid").InnerText '取oid的值也是正常的

'我想在这个循环里取到tid的值,我估计是我的写法不对,可能对for each的理解就有问题。求代码!
‘你不是取到tid了吗?
Next

Next

wang_pei_1984 2011-10-19
  • 打赏
  • 举报
回复
正在测试中~
huayy 2011-10-19
  • 打赏
  • 举报
回复
自己up,别沉了!

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧