//获取合同信息
string projectNo = Request.QueryString["projectNo"];
string Sql="select * from tableName where projectNo='+projectNo+'";
DAL.DALSelect xx = new DALSelect();
SqlDataReader reader = xx.ExecuteReader(Sql);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("/WebTest/DocumentManage/User.xml")); //xml文件路径
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("User");//xml所有节点的父节点
XmlNode root = xmlDoc.DocumentElement;
root.RemoveAll(); //每次写入xml文件的时候都清空原来所有的节点,避免重复的数据写入xml文件
while (reader.Read())
{
string ContractId = reader["ContractId"].ToString();
string ContractType = reader["ContractType"].ToString();
string PayMoneyNotId = reader["PayMoneyNotId"].ToString();
string CustName = reader["CustName"].ToString();
string PayMoney = reader["PayMoney"].ToString();
string PayMoneyLimitT = reader["PayMoneyLimitT"].ToString();
string PayMoneyLimitTUnit = reader["PayMoneyLimitTUnit"].ToString();
string ContractName = reader["ContractName"].ToString();
string ContractNo = reader["ContractNo"].ToString();
string ContractStartT = reader["ContractStartT"].ToString();
string ContractEndT = reader["ContractEndT"].ToString();
string ContractRemarks = reader["ContractRemarks"].ToString();
XmlElement el = xmlDoc.CreateElement("ContractInfo"); //添加ContractInfo节点
el.SetAttribute("Id", PayMoneyNotId); //添加ContractInfo节点的属性"Id"
el.SetAttribute("Name", ContractName); //添加ContractInfo节点的属性 "ContractName"
XmlElement xesub1 = xmlDoc.CreateElement("ContractType"); //添加ContractInfo节点的里的节点
xesub1.InnerText = ContractType;//设置文本节点
el.AppendChild(xesub1);
XmlElement xesub2 = xmlDoc.CreateElement("PayMoneyNotId");
xesub2.InnerText = PayMoneyNotId;//设置文本节点
el.AppendChild(xesub2);
XmlElement xesub3 = xmlDoc.CreateElement("CustName");
xesub3.InnerText = CustName;//设置文本节点
el.AppendChild(xesub3);
XmlElement xesub4 = xmlDoc.CreateElement("PayMoney");
xesub4.InnerText = PayMoney;//设置文本节点
el.AppendChild(xesub4);
XmlElement xesub5 = xmlDoc.CreateElement("PayMoneyLimitT");
xesub5.InnerText = PayMoneyLimitT;//设置文本节点
el.AppendChild(xesub5);
XmlElement xesub6 = xmlDoc.CreateElement("PayMoneyLimitTUnit");
xesub6.InnerText = PayMoneyLimitTUnit;//设置文本节点
el.AppendChild(xesub6);
XmlElement xesub7 = xmlDoc.CreateElement("ContractName");
xesub7.InnerText = ContractName;//设置文本节点
el.AppendChild(xesub7);
XmlElement xesub8 = xmlDoc.CreateElement("ContractNo");
xesub8.InnerText = ContractNo;//设置文本节点
el.AppendChild(xesub8);
XmlElement xesub9 = xmlDoc.CreateElement("ContractStartT");
xesub9.InnerText = ContractStartT;//设置文本节点
el.AppendChild(xesub9);
XmlElement xesub10 = xmlDoc.CreateElement("ContractEndT");
xesub10.InnerText = ContractEndT;//设置文本节点
el.AppendChild(xesub10);
XmlElement xesub11 = xmlDoc.CreateElement("ContractRemarks");
xesub11.InnerText = ContractRemarks;//设置文本节点
el.AppendChild(xesub11);
XmlElement xesub12 = xmlDoc.CreateElement("ContractId");
xesub12.InnerText = ContractId;//设置文本节点
el.AppendChild(xesub12);
xmldocSelect.AppendChild(el);
xmlDoc.Save(Server.MapPath("/WebTest/DocumentManage/User.xml")); //保存xml文件
}
}
User.xml最初文件
<?xml version="1.0" encoding="utf-8"?>
<User></User>