wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Modifying XML content using JDOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Modifying XML content using JDOM" Watch "Modifying XML content using JDOM" New topic
Author

Modifying XML content using JDOM

Nirban Dutta
Greenhorn

Joined: Jun 20, 2001
Posts: 9
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

Joined: Jun 20, 2001
Posts: 9
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Modifying XML content using JDOM