Code: Select all
private static void rewriteXmlDocument(Document document, File xmlFile) throws TransformerException, FileNotFoundException {
File temporaryFile = new File(xmlFile.getParent() + File.separator + "temporary.xml"); // write to a temporary file
DOMSource source = new DOMSource(document);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
if(temporaryFile.exists()) temporaryFile.delete(); // there is a trash
StreamResult result = new StreamResult(new FileOutputStream(temporaryFile));
transformer.transform(source, result);
xmlFile.delete(); // write succeeded, now we can delete the old
temporaryFile.renameTo(xmlFile); // rename temporary to old name
}
Code: Select all
org.docx4j
docx4j
6.1.2
org.glassfish.jaxb
jaxb-runtime
2.3.1
Code: Select all
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xml/serializer/TreeWalker
at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:818)
at AnanlyzeEmails/AnalyzeEmailsApplication.AnalyzeEmailsApp.rewriteXmlDocument(AnalyzeEmailsApp.java:170)
Mobile version