//组建xml文档 public string GetXml(PingZhengTemp PingZhengTemp, string path) { //string xml = new Dal.NcBill.ccpwgbg().ToNc(newdh, Server.MapPath("~/")); StringBuilder sb = new StringBuilder(); //表头 PingZhengTemp.id = System.Guid.NewGuid().ToString().ToUpper(); PingZhengTemp.date = PingZhengTemp.date; PingZhengTemp.year = PingZhengTemp.date.Substring(0, 4).ToString(); PingZhengTemp.month = PingZhengTemp.date.Substring(5, 2).ToString(); PingZhengTemp.voucher_type = PingZhengTemp.voucher_type.ToString(); string s1 = ReadTxt.Read(path + "Views\\NcModel\\1header.txt"); s1 = ReadTxt.ReplaceTxt(PingZhengTemp, s1); //表体 string s2 = ReadTxt.Read(path + "Views\\NcModel\\2body.txt"); StringBuilder sb2 = new StringBuilder(); var entry = PingZhengTemp.entry.ToList(); foreach (var i in entry) { if (!string.IsNullOrEmpty(i.xjl)) { i.item += "<item name=\"现金流量项目\">" + i.xjl + "</item>"; } if (i.fzhs != null) { var fzhs = i.fzhs.ToList(); foreach (var j in fzhs) { if (!string.IsNullOrEmpty(j.Hsame)) { i.item += "<item name=\"" + j.Hsame + "\">" + j.Hsvale + "</item>"; } } } } //替换 foreach (var i in entry) { string stemp = s2.ToString(); stemp = ReadTxt.ReplaceTxt(i, stemp); stemp = stemp.Replace("@item", ""); sb2.Append(stemp); } //表尾 string s3 = ReadTxt.Read(path + "Views\\NcModel\\3foot.txt"); string endstr = sb.Append(s1).Append(sb2.ToString()).Append(s3).ToString(); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(endstr); //写日志 string FilePath = path + "XMLDoc/" + PingZhengTemp.company + PingZhengTemp.date.ToString() + ".txt"; ReadTxt.Write(FilePath, xdoc.InnerXml); return(xdoc.InnerXml); }