tags:

views:

326

answers:

0

I have a docx template that I am saving as .xml and then parsing the content. Then I am generating a new updated word document. After the word document is generated I am unable to open it. It says " document corrupt ". I press ok. Then it says " Press OK if Do you want to retrieve the document ". I press ok. Then I get the updated document. This happens everytime. I have created the same program as stand alone java application. The document generated through the stand alone Java application opens without any errors. Could anyone provide me an insight into this ? I have used the same code for the server side also.

Here is the code that I use to generate the docuemnt.

try {
    // Prepare the DOM document for writing
    Source source = new DOMSource(doc);

    // Prepare the output file          
    FileOutputStream file = new FileOutputStream(filename);  

    Result result = new StreamResult(file);
    // Write the DOM document to the 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();

}