功能是为了实现调用快递接口,对快递运单的批量查询
功能初始页面
输入数据后
现在遇到的问题就是怎么动态添加xml节点,想实现的结果是
<BatchQueryRequest> <logisticProviderID>xxx</logisticProviderID> <clientID>xxx</clientID> <orders> <order> <mailNo>1111111111</mailNo> </order> <order> <mailNo>2222222222</mailNo> </order> </orders> </BatchQueryRequest>
后台代码
string orderNo = this.IndexwaybillNo.Value.Trim(); string clientId = "xxx"; string logisticProviderID = "xxx"; string[] rs = orderNo.Trim().Split('/'); string xml = "<BatchQueryRequest>" + "<logisticProviderID>" + logisticProviderID + "</logisticProviderID>" + "<clientID>" + clientId + "</clientID>" + "<orders>" + "</orders>" + "</BatchQueryRequest>"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); XmlNode xmlNode = xmlDoc.SelectSingleNode("BatchQueryRequest/orders"); foreach (string s in rs) { if (s.Trim().Length!= 10) { this.lblTime.Text = ""; Common.Alert("运单号输入不正确,请输入10位正确运单号"); } else if (!op.StrIsInt(s)) { this.lblTime.Text = ""; Common.Alert("运单号格式不正确,请输入10位正确运单号"); } else { orderNo = s; if (xmlNode != null) { XmlElement newElement = xmlDoc.CreateElement("order");//添加order节点 XmlElement etitle = xmlDoc.CreateElement("mailNo"); //添加mailNo节点 etitle.InnerXml = orderNo; newElement.AppendChild(etitle); xmlNode.AppendChild(newElement); } xmlDoc.LoadXml(xml); } }
刚开始接触xml,节点就是添加不上。求高人指点!!!!!!!