<?xml version="1.0" encoding="GBK"?>
-<data version="1.0"> -<trans_main> <trans_type>2</trans_type> <s_ent_name>XX公司</s_ent_name> <b_ent_name>XX公司</b_ent_name> <b_ent_type>0</b_ent_type> <b_licence_no/> <b_city_id/> <b_city_name/> <b_boro_id/> <b_boro_name/> <trans_date>2012-02-05</trans_date> <create_date>2012-02-10</create_date> <report_user>谷正艳</report_user> <user_link>15849772556</user_link> <if_network>0</if_network> </trans_main>
-<trans_detail> <trans_type>2</trans_type> <pass_num/> <goods_name>开塞露</goods_name> <drug_name/> <goods_manu/> <drug_ename/> <standard>20ml</standard> <form>中成药外用</form> <lot_num>110301.</lot_num> <uom>盒</uom> <trans_amount>40</trans_amount> <prices/> <trans_num/> <report_amount/> <validate_date>2013-02-28 00:00:01</validate_date> </trans_detail>
-<trans_detail> <trans_type>2</trans_type> <pass_num>国药准字(2002)</pass_num> <goods_name>妇炎洁洗液-180</goods_name> <drug_name/> <goods_manu/> <drug_ename/> <standard>180ml</standard> <form>中成药外用</form> <lot_num>110402</lot_num> <uom>并</uom> <trans_amount>10</trans_amount> <prices/> <trans_num/> <report_amount/> <validate_date>2013-03-31</validate_date> </trans_detail>
</data>[code=C#][/code]XML格式是这样的我怎么读取到数据库。
-<data version="1.0"> -<trans_main> <trans_type>2</trans_type> <s_ent_name>XX公司</s_ent_name> <b_ent_name>XX公司</b_ent_name> <b_ent_type>0</b_ent_type> <b_licence_no/> <b_city_id/> <b_city_name/> <b_boro_id/> <b_boro_name/> <trans_date>2012-02-05</trans_date> <create_date>2012-02-10</create_date> <report_user>谷正艳</report_user> <user_link>15849772556</user_link> <if_network>0</if_network> </trans_main>
-<trans_detail> <trans_type>2</trans_type> <pass_num/> <goods_name>开塞露</goods_name> <drug_name/> <goods_manu/> <drug_ename/> <standard>20ml</standard> <form>中成药外用</form> <lot_num>110301.</lot_num> <uom>盒</uom> <trans_amount>40</trans_amount> <prices/> <trans_num/> <report_amount/> <validate_date>2013-02-28 00:00:01</validate_date> </trans_detail>
-<trans_detail> <trans_type>2</trans_type> <pass_num>国药准字(2002)</pass_num> <goods_name>妇炎洁洗液-180</goods_name> <drug_name/> <goods_manu/> <drug_ename/> <standard>180ml</standard> <form>中成药外用</form> <lot_num>110402</lot_num> <uom>并</uom> <trans_amount>10</trans_amount> <prices/> <trans_num/> <report_amount/> <validate_date>2013-03-31</validate_date> </trans_detail>
</data>[code=C#][/code]XML格式是这样的我怎么读取到数据库。
解决方案 »
- c# 检测本地存在扫描仪以及其状态
- .ocx控件注册问题
- winform程序中comboBox控件怎样使用循环
- 关掉其它Form?解决后马上送分.
- 如何讓轉出來的excel中的表格的數據類型跟數據庫裡的一至。特別是如"123456"這種,數據庫裡是字串,但轉出來後變成數字了,在excel中還可以求和。
- winform treeview 中只有一个节点(根节点)时,如何显示+或-
- 愚翁:帮助看看我的问题。谢谢!
- Textbox(支持多行)如果在开发期通过设属性自动换行?如果开发可移动(C#)的工具栏和子窗口(VC中的bar之类的东东)
- 如何在C#中实现象Delphi的这样的一个功能
- Datatable转Excel后,怎么用代码实现Excel列宽的自动调整?
- 新人求问 c#中this的用法
- C#用同一个Timer同时实时的监测做两件事情,怎么做??
//======================== 下面是添加一个节点 =========================
XmlDocument xmlDoc = new XmlDocument();
// 主要代码:
xmlDoc.Load(Application.StartupPath + "\\data.xml");
//找到要添加处
XmlNode root = xmlDoc.SelectSingleNode("Employees"); //查找<Employees>
//下面是操作
XmlElement xe1 = xmlDoc.CreateElement("Node"); //创建一个<Node>节点
{
//设置属性
xe1.SetAttribute("genre", "张三");
xe1.SetAttribute("ISBN", "1-1111-1"); //设置该节点ISBN属性 XmlElement xesub1 = xmlDoc.CreateElement("title");
xesub1.InnerText = "C#入门帮助"; //设置文本节点
xe1.AppendChild(xesub1); //添加到<Node>节点中
XmlElement xesub2 = xmlDoc.CreateElement("author");
xesub2.InnerText = "高手";
xe1.AppendChild(xesub2);
XmlElement xesub3 = xmlDoc.CreateElement("price");
xesub3.InnerText = "158.3";
xe1.AppendChild(xesub3);
}
root.AppendChild(xe1);//添加到<Employees>节点中
xmlDoc.Save(Application.StartupPath + "\\data.xml");//============== 下面结果 =============================================
<?xml version="1.0" encoding="gb2312" standalone="yes"?>
<Employees>
<Node genre="李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>候捷</author>
<price>58.3</price>
</Node>
<Node genre="李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>候捷</author>
<price>58.3</price>
</Node>
</Employees>
变成如下:
<?xml version="1.0" encoding="gb2312" standalone="yes"?>
<Employees>
<Node genre="李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>候捷</author>
<price>58.3</price>
</Node>
<Node genre="李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>候捷</author>
<price>58.3</price>
</Node>
<Node genre="张三" ISBN="1-1111-1">
<title>C#入门帮助</title>
<author>高手</author>
<price>158.3</price>
</Node>
</Employees>
if (node != null)
{
string k1 = node.Value; //null
string k2 = node.InnerText;//Data Source=yf; user id=ctm_dbo;password=123
string k3 = node.InnerXml;//Data Source=yf; user id=ctm_dbo;password=123
node = null;
}
XmlElement perentNode = xel.ParentNode; //取得子节点 集合
XmlNodeList nodeList = xmlDoc.SelectSingleNode("Employees").ChildNodes;
//可用foreach 来遍历,
foreach(NodeList nl in nodeList )
{
// nl //这是每个子节点
//设属性
nl .SetAttribute("genre", "李赞红");//设置该节点genre属性
//取属性
if (nl .GetAttribute("genre") == "张三"){}
//设innerHtml
nl.InnerText = "CS从入门到精通";
//删除genre属性
xe.RemoveAttribute("genre");
}