File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Need to modify xml using dom4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Need to modify xml using dom4j" Watch "Need to modify xml using dom4j" New topic
Author

Need to modify xml using dom4j

Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Hi all,

I am new in dom4j and xml parsing. I need to modify the xml file. But I have no idea . I am trying to do but not succeed. Please help....
I have no idea so please help if i have done mistakes in core..but my goals is to modify the xml element..

following is code which i tried..

xml file...


I want to change above <desc> element with some other value.



I am trying to modify this file with some new value of <desc> by following code..

java file



after executing the above java file I am getting the following xml... but xml is not right...




thanks
with regards
Ranveer
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

I don't know what the "asXML" method does in dom4j, and I don't feel like hunting down its documentation on the web. So I'm just going to guess that you should be using some other method there. Like the getRootElement method for example. You didn't say why you wanted to do this or what the output should have been, so guessing is the only way forward.
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Paul Clapham wrote:I don't know what the "asXML" method does in dom4j, and I don't feel like hunting down its documentation on the web. So I'm just going to guess that you should be using some other method there. Like the getRootElement method for example. You didn't say why you wanted to do this or what the output should have been, so guessing is the only way forward.


Hi Paul,

thanks for reply.

actually I was getting follwoing extra line in output.xml file. asXML is simple parsing text to xml in dom4j. I am now able to modify the element in xml..
by following code (instead of asXML, because asXML method is adding "<?xml version="1.0" encoding="UTF-8"?>" line )



but still getting problem.
I am searching the element (by loop) when find, first remove that element and again adding the modified element on there. after that writing that xml again.

I looking forward to do same with XPath instead of loop. Because in my condition we know the element path.
please help..

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to modify xml using dom4j
 
Similar Threads
appending node to xml file
How To Retain Entity Reference Character While Reading XML
Unicode Problem in Struts using dom4j for xml parsing
xml creation
Xml/File Input/Output