首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net 循环添加节点,求帮助?该如何解决

2012-05-24 
asp.net 循环添加节点,求帮助???????C# codestring orderNo this.IndexwaybillNo.Valuestring clientId

asp.net 循环添加节点,求帮助???????

C# code
string orderNo = this.IndexwaybillNo.Value;            string clientId = "abc";             string logisticProviderID = "cbc";             string xml = "";            string[] rs = orderNo.Split('/');                       xml = "<BatchQueryRequest>" +                      "<logisticProviderID>" + logisticProviderID + "</logisticProviderID>" +                      "<clientID>" + clientId + "</clientID>" +                      "<orders>" +                                                "</orders>" +                  "</BatchQueryRequest>";                        foreach (string s in rs)            {                if (s.Length < 10 || !IsNumberic(s))                {                    this.lblTime.Text = "";                    Common.Alert("运单号输入不正确,请输入10位正确运单号");                }                else                {                    orderNo = s;                    XmlDocument xmlDoc = new XmlDocument();                    xmlDoc.LoadXml(xml);                    XmlNode xmlNode = xmlDoc.SelectSingleNode("BatchQueryRequest/orders");                    if (xmlNode != null)                    {                        XmlElement newElement = xmlDoc.CreateElement("order");//添加order节点                        XmlElement etitle = xmlDoc.CreateElement("mailNo"); //添加mailNo节点                        etitle.InnerText = orderNo.ToString();                        //Common.Alert(etitle);                        newElement.AppendChild(etitle);                        xmlNode.AppendChild(newElement);                    }                    xmlDoc.Save(xml);                }            }

我想给orders节点下循环添加多个order节点
实现以下效果
XML code
 <BatchQueryRequest>  <logisticProviderID>cbc</logisticProviderID>   <clientID>abc</clientID>   <orders>     <order>        <mailNo>1000000001</mailNo>    </order>    <order>        <mailNo>1000000002</mailNo>    </order>        <order>        <mailNo>1000000003</mailNo>    </order>  </orders>  </BatchQueryRequest>

到了xmlDoc.save(xml)就报错了。错误提示:路径中具有非法字符。

[解决办法]
xmlDoc.save(xml)这里有问题,xmlDoc.save(filename)这里参数应该是带路径的文件名

热点排行