zoukankan      html  css  js  c++  java
  • XML 克隆节点

    <?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);
                    }
                }
    
    
  • 相关阅读:
    后缀自动机学习笔记
    [bzoj4516][Sdoi2016]生成魔咒——后缀自动机
    [bzoj1692][Usaco2007 Dec]队列变换——贪心+后缀数组
    BZOJ4811 [Ynoi2017]由乃的OJ
    codeforces796E Exam Cheating
    BZOJ1004 [HNOI2008]Cards
    BZOJ1798 [Ahoi2009]Seq 维护序列seq
    BZOJ4785 [Zjoi2017]树状数组
    UOJ207 共价大爷游长沙
    POJ3768 Katu Puzzle
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/12559610.html
Copyright © 2011-2022 走看看