xml根据属性去重。如csprj去重
2024-09-29 21:26:11
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 = ; i < allNodes.Count - ; i++)
{
XmlElement node_Element = (XmlElement)allNodes[i];
string currentNodeValue = node_Element.GetAttribute("Include");
for (int j = i + ; 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 = @"..\..\upload\demo.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>
最新文章
- C# 操作excel单元格居中
- myeclipse 2014 除了 默认加载的derby
- 点击每个li节点,都弹出其文本值及修改
- IOS 其它语言比较-Objc与JAVA的比较
- POJ 2002 统计正方形 HASH
- ECharts使用心得总结(二)
- BZOJ 3165 Segment
- java服务器知识
- linux怎样修改用户权限
- JSP中的EL语言
- 客户调查(client)
- Raid类型
- c# 对加密的MP4文件进行解密
- 【liferay】3、liferay 添加spring支持
- Windows运行GitStats
- SQL Server使用sp_spaceused查看表记录存在不准确的情况
- String Reconstruction (并查集)
- Controller层aop
- IP段,ASN与BGP之间的关系
- SharePoint下在Feature中动态Register/Remove HttpModule
热门文章
- Netty高性能之Reactor线程模型
- 【论文笔记】Training Very Deep Networks - Highway Networks
- 确保安全的HTTPS(对HTTP加密的几种技术,前端面试常问)第一篇
- mysql memory engine
- 修改zerolog使log输出的文件名可以在goland里自动定位--技巧
- [转]SpringMVC<;from:form>;表单标签和<;input>;表单标签简介
- [转]Ext.grid常用属性和方法
- thinkphp前台模版字符串截取
- 【.Net】Thread.Start()与ThreadPool.QueueUserWorkItem()的区别
- Linux下的微秒级别的定时器