Modify XML file in Java using DOM parser

In one of the earlier post we saw How to parse an XML using DOM parser.
In this post we will see how to modify XML file in Java using DOM parser. We can add, update and delete any nodes/elements in XML using DOM parsers in Java.

Lets see the example. We have the below XML that we will modify

Original XML

Modify XML file in Java using DOM parser

Now we will perform the following actions on the XML
1. Update the Salary Of the First Employee to 6500
2. Add element “Age” to the First Employee
3. Remove the department from Second Employee

Modified XML

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn