xml传参

Posted wuln

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml传参相关的知识,希望对你有一定的参考价值。

前端调用后端方法时要传递多个参数,在前端js中拼接xml形式的字符串:

 1 var args = "<?xml version=‘1.0‘ encoding=‘utf-8‘ ?>";
 2 args += "<Bill>";
 3 for (var i = 0; i < dataChange.length; i++) {    
 4     if (dataChange[i].bghsl != undefined) {
 5         if (dataChange[i].gcsl != undefined)
 6             args += "<Item PrimaryKey = ‘" + data.items[i].data.gxid + "‘ SSBM = ‘" + data.items[i].data.ssbm + "‘ BillCode = ‘" + data.items[i].data.qdbh + "‘ ProCount = ‘" + dataChange[i].gcsl + "‘ />";
 7         else
 8             args += "<Item PrimaryKey = ‘" + data.items[i].data.gxid + "‘ SSBM = ‘" + data.items[i].data.ssbm + "‘ BillCode = ‘" + data.items[i].data.qdbh + "‘ ProCount = ‘" + 0 + "‘ />";        
 9     }
10 }
11 args += "</Bill>";

后端接收参数并解析:

 1 protected override string UpdateProCount(string strXml)
 2 {
 3     XmlDocument doc = new XmlDocument();
 4     doc.LoadXml(strXml);
 5     XmlElement root = doc.DocumentElement;
 6 
 7     StringBuilder strSql = new StringBuilder();
 8     StringBuilder strqd = new StringBuilder();
 9     foreach (XmlElement item in root.ChildNodes)
10     {
11         strSql.AppendFormat("update T_JJJ_JGBWQDGX set F_GCSL={0},F_BGHSL = isnull(F_BGSL,0) + {0},F_BGHJE = (isnull(F_BGSL,0) + {0}) * F_BGHDJ ", item.GetAttribute("ProCount"));
12         strSql.AppendFormat("where F_ID = {0};", item.GetAttribute("PrimaryKey"));
13         strqd.AppendFormat("‘{0}‘,", item.GetAttribute("BillCode"));
14     }
15     int resault = GSqlDataAccess.ExecuteNonQuery("default", strSql.ToString(), null);
16     if (resault == 0)
17         return "保存失败!";
18     else
19     {
20         string fid = root.FirstChild.Attributes["PrimaryKey"].Value;
21         strSql.Clear();
22         string tmp = strqd.ToString();
23         strSql.Append("declare @BDBH number(19,0);");
24         strSql.AppendFormat("select @BDBH = F_BDBH from T_JJJ_SGGCLQDFJ where F_ID = (select F_SGGCLQDFJ_ID from T_JJJ_JGBWQDGX where F_ID = {0});", fid);
25         strSql.Append("select sum(F_GCSL) as CountSum,F_QDBH,F_BDBH from T_JJJ_SGGCLQDFJ ");
26         strSql.Append("inner join T_JJJ_JGBWQDGX on T_JJJ_SGGCLQDFJ.F_ID = T_JJJ_JGBWQDGX.F_SGGCLQDFJ_ID ");
27         strSql.AppendFormat("where T_JJJ_SGGCLQDFJ.F_BDBH = @BDBH and F_QDBH in {0} group by F_QDBH,F_BDBH ", "(" + tmp.Substring(0, tmp.Length - 1) + ")");
28         IDataReader reader = GSqlDataAccess.SelectReader("default", strSql.ToString(), null);
29         strSql.Clear();
30         while (reader.Read())
31         {
32             strSql.AppendFormat("update T_JJJ_SGHTGCLQD set F_HLSL = {0}, ", reader["CountSum"].ToString() == "" ? "0" : reader["CountSum"].ToString());
33             strSql.AppendFormat("F_HLJE = {0} * (isnull(F_HTDJ,F_BGHDJ)) ", reader["CountSum"].ToString() == "" ? "0" : reader["CountSum"].ToString());
34             strSql.AppendFormat("where F_CODE = ‘{0}‘ and F_SSBM = {1};", reader["F_QDBH"].ToString(), reader["F_BDBH"].ToString());
35         }
36         reader.Dispose();
37         resault = GSqlDataAccess.ExecuteNonQuery("default", strSql.ToString(), null);
38         if (resault > 0)
39 
40             return "保存成功!";
41 
42         else
43             return "保存失败!";
44     }
45 }

 

以上是关于xml传参的主要内容,如果未能解决你的问题,请参考以下文章

Reactreact概述组件事件

xml Eclipse模板(代码片段)检查参数并最终抛出IllegalArgumentException

需要示例代码片段帮助

从 XML 声明片段获取 XML 编码:部分内容解析不支持 XmlDeclaration

springboot开启矩阵传参MatrixVariable

创建片段而不从 java 代码实例化它