I have a docx template that I save as .xml and then parse the contents. Then I create a new updated document. After creating a Word document, I cannot open it. It says that "the document is damaged." I click OK. Then he says: “Click OK if you want to receive the document.” I click OK. Then I get an updated document. It happens every time. I created the same program as a stand-alone Java application. A document created through a stand-alone Java application opens without any errors. Can anyone give me an idea about this? I also used the same code for the server side.
Here is the code that I use to create the document.
try {
Source source = new DOMSource(doc);
FileOutputStream file = new FileOutputStream(filename);
Result result = new StreamResult(file);
Transformer xformer = TransformerFactory.newInstance()
.newTransformer();
xformer.transform(source, result);
file.close();
} catch (TransformerConfigurationException e) {
System.out.println("Transformation Configuration Excepiton in WriteXMLFile");
} catch (TransformerException e) {
System.out.println("Transformation Excepiton in WriteXMLFile");
} catch (Exception e) {
System.out.println("Transformation Excepiton in WriteXMLFile");
e.printStackTrace();
}