• 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

Modifying XML content using JDOM

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using JDOM for manipulating my external XML file from within JSP. For retrieving information, it is working fine, but while modifying the Text of an element, it is not chaning the text , also it is not showing any error.
I have used both SAXBuilder and DOMBuilder classes and tried to change the text of particular element like:
Element nm = pt.getChild("name");
//where pt is the parent element of element "name"
nm = nm.setText("New Name");
But its not changing the text of the element to "New Name".
Can anyone help me?
Thanx in advance
 
Nirban Dutta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hurrey , I have done it.
What I did, I modified the Document(ie JDOM Tree) and then transfer the changes to actual xml document.
The code is:
try
{
SAXBuilder sb = new SAXBuilder();
Document db = sb.build(new File("D:/weblogic/wlserver6.0/config/mydomain/applications/DefaultWebApp_myserver/jsp/hotel/myHotel.xml"));
Element rtel = db.getRootElement();
Element hotel = rtel.getChild("hotel");
Element general = hotel.getChild("general");
Element name = general.getChild("name");
name.setText(hotelname);
XMLOutputter xout = new XMLOutputter();
xout.output(db,(Writer)(new FileWriter(new File("D:/weblogic/wlserver6.0/config/mydomain/applications/DefaultWebApp_myserver/jsp/hotel/myHotel.xml"))));
}
Anybody, who is interested in JDOM, can use JDOM very easily, it is very easy as compared to XML4J.
Cheers
reply
    Bookmark Topic Watch Topic
  • New Topic