标签:des style tar strong 数据 string
将XML格式字符串,写入数据集的表1中
命名空间:using System.Xml;
string strRead;//strRead为以下xml值
XmlDocument xd = new XmlDocument();
xd.LoadXml(strRead);
XmlNodeList nodeList = xd.SelectSingleNode("root").ChildNodes;//获取bookstore节点的所有子节点
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型
if (xe.Name == "trades")
{
XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode xn1 in nls)//遍历
{
DataRow dr = dataSet1.Tables["Table1"].NewRow();
for (int item = 0; item < xn1.ChildNodes.Count; item++)
{
XmlElement xe2 = (XmlElement)xn1.ChildNodes[item];//转换类型
dr[xe2.Name] = xe2.FirstChild.Value;
}
dr["goods_number1"] = 0;
dataSet1.Tables["Table1"].Rows.Add(dr);
}
}
}
XML数据格式: strRead
<?xml version="1.0" encoding="UTF-8"?>
<root>
<trades>
<trade><goods_id>1328</goods_id> <goods_sn>3021</goods_sn> <goods_name>PBA YangSang 矿物丝柔散粉806-A2柔白13g</goods_name> <goods_number>1</goods_number> </trade>
<trade> <goods_id>1303</goods_id> <goods_sn>1031</goods_sn> <goods_name>PBA 芭蓓萃 提拉紧致蚕丝面膜25g</goods_name> <goods_number>1</goods_number></trade>
</trades>
</root>
C# 将XML格式字符串,写入数据集的表中 XML解析,布布扣,bubuko.com
C# 将XML格式字符串,写入数据集的表中 XML解析
标签:des style tar strong 数据 string
原文地址:http://www.cnblogs.com/iwin9999/p/3804593.html