• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need to modify xml using dom4j

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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..

reply
    Bookmark Topic Watch Topic
  • New Topic