C# xml文件读取节点写入数据
2012-08-09 16:57
393 查看
<enums>
<catagory id="SalesOrderType">
<value description="订单">0</value>
<value description="退货单">1</value>
</catagory>
<catagory id="SalesOrderStatus">
<value description="已拆分">-30</value>
<value description="已合并">-20</value>
<value description="已撤销">-10</value>
<value description="未确认">0</value>
<value description="已确认">10</value>
<value description="已审核">20</value>
<value description="已打印">30</value>
<value description="已取货">40</value>
<value description="已验货">50</value>
<value description="已包装">60</value>
<value description="已发货">70</value>
<value description="已核销">80</value>
</catagory>
</enums>
XmlDocument xmldoc = new XmlDocument();
//xmldoc.Load(Directory.GetCurrentDirectory() + "\\enums.xml"); //Debug调试
xmldoc.Load(Path.Combine(Application.StartupPath,"enums.xml"));
XmlNodeList topM = xmldoc.DocumentElement.ChildNodes; //得到顶层节点列表
foreach (XmlElement element in topM)
{
if (element.Name.ToLower() == "catagory")
{
string catagory = element.Attributes["id"].Value;
XmlNodeList nodelist = element.ChildNodes; //得到该节点的子节点
if (nodelist.Count > 0)
{
foreach (XmlElement el in nodelist) //读元素值
{
int keyint =int.Parse(el.InnerText);
string value= el.Attributes["description"].Value;
tenum=new Tenum(catagory,keyint,value);
//插入数据
}
}
}
}
<catagory id="SalesOrderType">
<value description="订单">0</value>
<value description="退货单">1</value>
</catagory>
<catagory id="SalesOrderStatus">
<value description="已拆分">-30</value>
<value description="已合并">-20</value>
<value description="已撤销">-10</value>
<value description="未确认">0</value>
<value description="已确认">10</value>
<value description="已审核">20</value>
<value description="已打印">30</value>
<value description="已取货">40</value>
<value description="已验货">50</value>
<value description="已包装">60</value>
<value description="已发货">70</value>
<value description="已核销">80</value>
</catagory>
</enums>
XmlDocument xmldoc = new XmlDocument();
//xmldoc.Load(Directory.GetCurrentDirectory() + "\\enums.xml"); //Debug调试
xmldoc.Load(Path.Combine(Application.StartupPath,"enums.xml"));
XmlNodeList topM = xmldoc.DocumentElement.ChildNodes; //得到顶层节点列表
foreach (XmlElement element in topM)
{
if (element.Name.ToLower() == "catagory")
{
string catagory = element.Attributes["id"].Value;
XmlNodeList nodelist = element.ChildNodes; //得到该节点的子节点
if (nodelist.Count > 0)
{
foreach (XmlElement el in nodelist) //读元素值
{
int keyint =int.Parse(el.InnerText);
string value= el.Attributes["description"].Value;
tenum=new Tenum(catagory,keyint,value);
//插入数据
}
}
}
}
相关文章推荐
- C#程序中:如何向xml文件中写入数据和读取数据
- C#实现xml文件的读取与写入简单实例
- C#中读取xml文件指定节点
- C#程序中:如何向xml文件中插入节点(数据)
- C# 读取写入数据到ACCESS数据库基于FRAMEWORK2.0
- C#程序中:如何向xml文件中插入节点(数据)
- C#下 读取xml节点的数据总结 .txt
- C#中NPOI操作excel之读取和写入excel数据
- C#xml文件的读取写入
- C#从数据库读取数据到DataSet并保存到xml文件
- C#中读取xml文件指定节点
- C#下 读取xml节点的数据总结 .txt
- [转] C#下 读取xml节点的数据总结
- C#读取Excel数据并重新写入Excel
- 转] C#下 读取xml节点的数据总结
- 使用C#写入并保存为*.txt和读取数据
- C#中读取xml文件指定节点
- C#下读取xml节点的数据总结
- 读取XML文件节点下面的数据信息
- C#中创建、打开、读取、写入、保存Exce,C#如何向EXCEL写入数据