- Code: Select all
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File("c:\\byggestr.docx"));
MainDocumentPart docPart = wordMLPackage.getMainDocumentPart();
Document doc = XmlUtils.marshaltoW3CDomDocument(docPart.getJaxbElement());
Document data = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("c:\\byggestr.xml");
modifyTableRows(doc, data);
docPart.setJaxbElement((org.docx4j.wml.Document)XmlUtils.unmarshal(doc));
CustomXmlDataStoragePart customXmlDataStoragePart = (CustomXmlDataStoragePart) wordMLPackage.getCustomXmlDataStorageParts().get("{A61EE2AE-F111-4B83-8C9C-F3BECEA1AD12}");
CustomXmlDataStorage customXmlDataStorage = customXmlDataStoragePart.getData();
printNode(data, "");
customXmlDataStorage.setDocument(data);
wordMLPackage.save(new java.io.File("c:\\fkf.docx"));
The printNode subrutine correctly prints the xml of the data with the correct encoding (ISO-8859-1)
The xml file "c:\byggestr.xml" contains "<?xml version="1.0" encoding="ISO-8859-1"?>" and it contains norwegian special characters and is saved in ANSI format, ...