Element child1 = dct.createElement("Name");
// Get the root node so we can explore its children
Element root = dct.getDocumentElement();
// Get the element from the user..
Text text1 = dct.createTextNode(name);
// Append the element to existing XML file
When I add the element "Hello" to the books.xml file for the first time, system appended the element Hello in books.xml file.. but for the second time , it overwrite the hello .. How can i append the element to existing file.. ?
Joined: May 31, 2011
The issue is that every a new DOM document gets created and written into the file. Check before you add whether the existing file (BN.xml) has already nodes or not.
Next time please UseCodeTags - I have added and updated the code below. See how good it looks.
Joined: Nov 02, 2011
Thank you so much John for spending time to read my code and gave suggestion..