i am trying to update elements in xml file using jdom, but somehow after whole operation file is not getting updated. below is my code:+
public int editServer(String[] server) {
int response = 0;
int validate = 0;
try {
File inputFile = new File(fileName);
saxBuilder = new SAXBuilder();
document = saxBuilder.build(inputFile);
classElement = document.getRootElement();
List<Element> voiceServers = classElement.getChildren();
for (int temp = 0; temp < voiceServers.size(); temp++) {
Element vServer = voiceServers.get(temp);
serverName = vServer.getChild("ServerName").getText();
type = vServer.getChild("Type").getText();
String metaData[] = { "ServerName", "IP", "Port", "UserName", "Password", "DataBase", "Type", "Status" };
if (serverName.equalsIgnoreCase(server[0].toString()) && type.equalsIgnoreCase(server[6].toString())) {
// 2 : deleted
validate = validateServer(server);
if (server.length == metaData.length && validate != 1) {
for (int i = 1; i < metaData.length; i++) {
System.out.println("Previous Value : " + vServer.getChild(metaData[i]).getText());
vServer.getChild(metaData[i]).setText(server[i]);
System.out.println("New Value : " + vServer.getChild(metaData[i]).getText());
}
System.out.println("DOne Save...");
break;
}
// vServer.getChild("ServerName").setText(text)
} else {
response = 500;
}
}
FileWriter writer = new FileWriter(fileName);
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
outputter.output(document, writer);
response = 2;
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return response;
}
and below is console response which i am printing before and after values of child.