Element child1 = dct.createElement("Name");
// Get the root node so we can explore its children
Element root = dct.getDocumentElement();
root.appendChild(child1);
// Get the element from the user..
Text text1 = dct.createTextNode(name);
// Append the element to existing XML file
root.getLastChild().appendChild(text1);
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.. ?
John Jai
Rancher
Joined: May 31, 2011
Posts: 1372
posted
0
Hi Rt,
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.
Booma Devi
Ranch Hand
Joined: Nov 02, 2011
Posts: 32
posted
0
Thank you so much John for spending time to read my code and gave suggestion..