Remove duplicate nodes in XML file

  • Thread starter Thread starter dazzle
  • Start date Start date
D

dazzle

I have an XML file and I would like to remove duplicate nodes within it
but I can't get my head round on how to do this.

Example XML file:

<root>

<plugin>
<title>A9</title>
<url>some url</url>
<number>0001</number>
</plugin>

<plugin>
<title>A9</title>
<url>some url</url>
<number>0002</number>
</plugin>

<plugin>
<title>BBC</title>
<url>some url</url>
<number>0003</number>
</plugin>

</root>

End up with:

<root>

<plugin>
<title>A9</title>
<url>some url</url>
<number>001</number>
</plugin>

<plugin>
<title>BBC</title>
<url>some url</url>
<number>003</number>
</plugin>

</root>

Any help and/or code samples would be useful.
 
By duplicate I'm guessing you mean where the titles are the same.

Create a list and loop through all your nodes. in the loop place the
title node into the list. If there is already a node with this title,
remove the current item from the xml file.
 
Back
Top