We help IT Professionals succeed at work.
Get Started

Removing information on Duplicate XML Nodes

199 Views
Last Modified: 2016-09-13
Hi,
I have the following XML

<?xml version="1.0" encoding="UTF-8"?>
<FILES ORIGINALFILE="TEST.xml">
      <FILETYPE NUMBER="ABC">
            <INFORMATION>
                  <COMPLETE>0</COMPLETE>
                  <TESTRESULTS>0</TESTRESULTS>
                  <CODE>STDEDF</CODE>
            </INFORMATION>
            <CINFO>
                  <KEY NAME="AAAA">C:\TEST\A</KEY>
                  <KEY NAME="BBBB">C:\TEST\B</KEY>
            </CINFO>
            <CUSTOM>
                  <PART="12345-1233">AB12345</PART>
                  <PART="JA1234">BD1234</PART>
            </CUSTOM>
            <INFORMATION>
                  <AGE>220</AGE>
                  <TIME>12:00:07</TIME>
                  <COMPLETE>0</COMPLETE>
                  <ULTS>0</ULTS>
            </INFORMATION>
            <CINFO>
                  <KEY NAME="CCCC">C:\TEST\C</KEY>
                  <KEY NAME="DDDD">C:\TEST\D</KEY>
            </CINFO>
            <CUSTOM>
                  <PART="12345-1233">BB12345</PART>
                  <PART="JA1234">CC1234</PART>
            </CUSTOM>
            <INFORMATION>
                  <NAME>TEST</NAME>
                  <TYPE>MOUSE</TYPE>
                  <TEST>TRUE</TEST>
                  <STATION>NODATA</STATION>
            </INFORMATION>
            <CINFO>
                  <KEY NAME="CCCC">C:\TEST\E</KEY>
                  <KEY NAME="DDDD">C:\TEST\F</KEY>
            </CINFO>
            <CUSTOM>
                  <PART="12345-1233">FF12345</PART>
                  <PART="JA1234">GG1234</PART>
            </CUSTOM>
      </FILETYPE>
</FILES>


How do I remove the Duplicate <INFORMATION>, <CINFO> and <CUSTOM> nodes.. I would like to keep only the newest Nodes like:
<?xml version="1.0" encoding="UTF-8"?>
<FILES ORIGINALFILE="TEST.xml">
      <FILETYPE NUMBER="ABC">
            <INFORMATION>
                  <NAME>TEST</NAME>
                  <TYPE>MOUSE</TYPE>
                  <TEST>TRUE</TEST>
                  <STATION>NODATA</STATION>
            </INFORMATION>
            <CINFO>
                  <KEY NAME="CCCC">C:\TEST\E</KEY>
                  <KEY NAME="DDDD">C:\TEST\F</KEY>
            </CINFO>
            <CUSTOM>
                  <PART="12345-1233">FF12345</PART>
                  <PART="JA1234">GG1234</PART>
            </CUSTOM>
      </FILETYPE>
</FILES>

Thank you!
Comment
Watch Question
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 2 Answers and 24 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE