java/xml help required

megavan

Disciple
I wrote the below code to change the value of an element in an xml file:

Document doc;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

try {

DocumentBuilder builder = factory.newDocumentBuilder();

doc=builder.parse(new File("C:/xmlapp/xmlfile.xml"));
NodeList nl=doc.getElementsByTagName("EmpNo");

Node n=nl.item(0);

//String str=n.getNodeValue();

n.setTextContent("92042");

System.out.println(n.getTextContent());

}

catch (SAXParseException spe) {
spe.printStackTrace();
}
catch (SAXException sxe) {
sxe.printStackTrace();
}
catch (ParserConfigurationException pce) {
pce.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}

The program seems to change the value of the element which I made sure by printing the value on the screen. But the value inside the actual file seems to remain the same as before. How do i remedy that?
 
Back
Top