生成xml文档两种方法
1、方法1
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.Append("<Root>");
Random rad = new Random();
int value = rad.Next(1000, 10000);
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());//生成xml文件
string year = DateTime.Now.Year.ToString();
string month = DateTime.Now.Month.ToString();
if (month.Length < 2) { month = "0" + month; }
string day = DateTime.Now.Day.ToString();
if (day.Length < 2) { day = "0" + day; }
string hour = DateTime.Now.Hour.ToString();
if (hour.Length < 2) { hour = "0" + hour; }
string minute = DateTime.Now.Minute.ToString();
if (minute.Length < 2) { minute = "0" + minute; }
string second = DateTime.Now.Second.ToString();
if (second.Length < 2) { second = "0" + second; }
//文件名称:Iv_河北_20121129132421_随机值.xml
string name = "Iv_" + dsProvince.Tables[0].Rows[j][0].ToString().Trim() + "_" + year + month + day + hour +minute + second + "_" + value.ToString() + ".xml";
doc.Save("D://UnicomInterface/UnicomSend_back/" + name);