Click here to Skip to main content
15,896,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to remove duplicate data from xml using C#

For example:
<root>
<text>work
questions
<link>http://sample.com/new</link>

<root>
<text>work2
questions
<link>http://sample.com/new</link>


In the above <link> is repeated. I want unique data based on link tag. I want to delete the entire duplicate record. In the above example delete 2nd root tag because link tag is repeated tow rows.

Please anyone help me.

Thank you........
Posted

1 solution

I would use LINQ to XML. then

C#
xdoc.Root.Elements("root").GroupBy(i=> (string)i.Element("link"))
	.SelectMany(g => g.Skip(1))
	.Remove();
 
Share this answer
 
Comments
NagaRaju Pesarlanka 1-May-14 5:02am    
Thank you.
Is there any possible through without linq.
NagaRaju Pesarlanka 2-May-14 2:36am    
Thank you.

This code is working perfectly. Thank you very much.

But I want load multiple xml files.
Please help me......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900