Appending a new node or a child node using Dom4j
I am s开发者_高级运维tuck 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.
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");
精彩评论