-1

I am stuck at updating an existing XML document. I have to add another element to the root node. I need to append it, but using XMLWriter, it is overriding the object and all the old data is lost. How can I add another node to the exisitng document?

That is, appending. I am using the Dom4j library.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user896456
  • 59
  • 3
  • 8

1 Answers1

0

XMLWriter is not the way to go. You can append, delete or otherwise manipulate nodes quite easily using the methods in the Node class and its subclasses. For example:

Element root = document.getRootElement();
Element author = root.addElement("author");
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Simone Gianni
  • 11,426
  • 40
  • 49
  • how to load an existing document to append more data and save it once the job is done? dom4j doesn't have much support:( – user896456 Aug 25 '11 at 15:11
  • 1
    @user896456, why don't you read the documentation at http://dom4j.sourceforge.net/dom4j-1.6.1/ ? Start with the cookbook section. – forty-two Aug 25 '11 at 15:41