由于没有使用Docx4jDriver类,因此内存不足,这使得diff问题更容易解决,方法是先执行段落级别的diff。
像这样使用它:
Body newerBody = ((document)newerPackage.getMaindocumentPart().getJaxbElement()).getBody(); Body olderBody = ((document)olderPackage.getMaindocumentPart().getJaxbElement()).getBody(); // 2. Do the differencing java.io.StringWriter sw = new java.io.StringWriter(); Docx4jDriver.diff( XmlUtils.marshaltoW3CDomdocument(newerBody).getdocumentElement(), XmlUtils.marshaltoW3CDomdocument(olderBody).getdocumentElement(), sw); // 3. Get the result String contentStr = sw.toString(); System.out.println("Result: nn " + contentStr); Body newBody = (Body) org.docx4j.XmlUtils .unmarshalString(contentStr);


