I am attempting to go through an XML file and take out certain duplicate entries.
If I have this as input :
<root>
<node id="121212" action="Loop" year="1995"/>
<node id="568512" action="Draw" year="1995"/>
<node id="261287" action="Create" year="1995"/>
<node id="261287" action="Create" year="2005"/>
<node id="261287" action="Activate" year="1990"/>
<node id="261287" action="Activate" year="2005"/>
<node id="261287" action= "Destroy" year="2005"/>
</root>
I want this output:
<root>
<node id="121212" action="Loop" year="1995"/>
<node id="568512" action="Draw" year="1995"/>
<node id="261287" action= "Destroy" year="2005"/>
</root>
The logic is
If there are duplicate entries with the SAME ID, take the element with the maximum year and delete the others. If there remain elements with duplicate year attributes but different action attributes, just take the last element.
Now, I know I can do this with loops, which is ugly (take the list of IDs that appear more than once, loop through the XML and for each ID loop through the dups and perform deletions).
Is there any way to do this cleanly with E4X or the list.contains method?