开发者

Appending a new node or a child node using Dom4j

开发者 https://www.devze.com 2023-03-30 14:07 出处:网络
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 da

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号