Remove duplicate nodes in XML file

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.
 
R

Ray Booysen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,250
Members
46,848
Latest member
Graciela Mitchell

Latest Threads

Top