<?xml version="1.0" encoding="UTF-8"?> <request> <criteriaList> <criteria> <warehouseCode>仓库编码, string(50), 必填</warehouseCode> <ownerCode>货主编码,string(50), 必填</ownerCode> <itemCode>商品编码,string(50),必填</itemCode> <itemId>仓储系统商品 ID, string(50)</itemId> </criteria>
<criteria>
<warehouseCode>仓库编码, string(50), 必填</warehouseCode>
<ownerCode>货主编码,string(50), 必填</ownerCode>
<itemCode>商品编码,string(50),必填</itemCode>
<itemId>仓储系统商品 ID, string(50)</itemId>
</criteria>
<criteria>
<warehouseCode>仓库编码, string(50), 必填</warehouseCode>
<ownerCode>货主编码,string(50), 必填</ownerCode>
<itemCode>商品编码,string(50),必填</itemCode>
<itemId>仓储系统商品 ID, string(50)</itemId>
</criteria>
</criteriaList> </request>
客户给的参数形式xml是这样的,所以在我抛送数据的时候,criteriaList是可以容纳多个的;那么怎么克隆出来多个呢:
try { XmlDocument xdi = new XmlDocument(); xdi.Load(("doc/InventorySync.xml"));//加载出来整个文档 XmlNode xd = xdi.SelectSingleNode("request/criteriaList/criteria");//要复制的节点,criteria这个节点下还有要复制的字段 xdi.SelectSingleNode("request/criteriaList").InnerXml = "";//这个是把xml中带有的原有的criteria除去 for (int i = 0; i < 10; i++) { XmlNode xdx = xd.Clone(); xdx.SelectSingleNode("warehouseCode").InnerXml = i.ToString(); xdx.SelectSingleNode("ownerCode").InnerXml = i.ToString(); xdx.SelectSingleNode("itemCode").InnerXml = i.ToString(); xdx.SelectSingleNode("itemId").InnerXml = i.ToString(); xdi.SelectSingleNode("request/criteriaList").AppendChild(xdx); } }