zoukankan      html  css  js  c++  java
  • xml根据属性去重。如csprj去重

     public static void distinct(string filePath)
            {
                //1、创建XML文档对象
                XmlDocument doc = new XmlDocument();
    
                //2、加载指定路径的XML
                doc.Load(filePath);
    
                //3、获得根节点
                XmlElement root = doc.DocumentElement;
    
                //4-1、获得根节点的所有子节点
                XmlNodeList allNodes = root.ChildNodes;
                for (int i = 0; i < allNodes.Count - 1; i++)
                {
                    XmlElement node_Element = (XmlElement)allNodes[i];
                    string currentNodeValue = node_Element.GetAttribute("Include");
                    for (int j = i + 1; j < allNodes.Count; j++)
                    {
                        XmlElement node_Element_temp = (XmlElement)allNodes[j];
                        if (node_Element_temp.GetAttribute("Include") == currentNodeValue)
                        {
                            node_Element_temp.ParentNode.RemoveChild(node_Element_temp);
                            j--;
                            continue;
                        }
                    }
                }
                doc.Save(filePath);
            }

    调用

     string path = @"....uploaddemo.xml";

      distinct(path);

    <?xml version="1.0" encoding="utf-8"?>
    <ItemGroup>
      <Compile Include="1" />
      <Compile Include="1" />
      <Compile Include="1" />
      <Compile Include="2" />
      <Compile Include="3" />
      <Compile Include="1" />
      <Compile Include="1" />
    </ItemGroup>
  • 相关阅读:
    安卓系统的文件管理神器Solid Explorer(v2.2)
    地月距离竟然如此遥远
    Android在争议中逃离Linux内核的GPL约束【转】
    gearman
    PHP基础学习
    函数式编程
    有向图的实现
    无向图的实现
    百度地图API获取数据
    python队列的实现
  • 原文地址:https://www.cnblogs.com/gaocong/p/7413077.html
Copyright © 2011-2022 走看看