Page 1 of 1

Compare documents failing.

PostPosted: Sat Feb 03, 2018 7:31 am
by Mark S
Hi I am trying to use the Compare Documents sample and it seems to be failing on the creation of a new document step. It produces the difference no problem.

The failing line:
Body newBody = (Body) XmlUtils.unwrap(
XmlUtils.unmarshalString(contentStr));

The exception(please let me know if you need the full stack):
java.lang.Throwable: null
at org.docx4j.jaxb.JaxbValidationEventHandler.handleEvent(JaxbValidationEventHandler.java:186)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:716)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:109)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:90)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:247)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:556)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:538)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:153)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:380)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2787)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:243)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:214)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:125)
at org.docx4j.XmlUtils.unmarshalString(XmlUtils.java:558)
at org.docx4j.XmlUtils.unmarshalString(XmlUtils.java:531)
at com.fhlmc.securitization.bookBuilder.poc.tests.TestCompare.main(TestCompare.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
2018-02-02 15:21:28.619 INFO [main] o.d.XmlUtils - encountered unexpected content; pre-processing
2018-02-02 15:21:28.619 DEBUG [main] o.d.u.ResourceUtils - docx4j.jaxb.JaxbValidationEventHandler resolved to custom-preprocessor.xslt
2018-02-02 15:21:28.619 DEBUG [main] o.d.u.ResourceUtils - Attempting to load: custom-preprocessor.xslt
2018-02-02 15:21:28.620 DEBUG [main] o.d.u.ResourceUtils - Trying Thread.currentThread().getContextClassLoader()
2018-02-02 15:21:28.623 WARN [main] o.d.u.ResourceUtils - Couldn't get resource: custom-preprocessor.xslt
2018-02-02 15:21:28.623 WARN [main] o.d.u.ResourceUtils - custom-preprocessor.xslt: custom-preprocessor.xslt not found via classloader.
2018-02-02 15:21:28.623 WARN [main] o.d.u.ResourceUtils - Property docx4j.jaxb.JaxbValidationEventHandler resolved to missing resource custom-preprocessor.xslt; using org/docx4j/jaxb/mc-preprocessor.xslt
2018-02-02 15:21:28.624 DEBUG [main] o.d.u.ResourceUtils - Attempting to load: org/docx4j/jaxb/mc-preprocessor.xslt
2018-02-02 15:21:28.641 INFO [main] o.d.XmlUtils - Using org.apache.xalan.transformer.TransformerImpl
2018-02-02 15:21:28.641 INFO [main] o.d.XmlUtils - Working around https://issues.apache.org/jira/browse/XALANJ-2419
method: xml
2018-02-02 15:21:28.654 WARN [main] o.d.j.JaxbValidationEventHandler - [ERROR] : unexpected element (uri:"http://www.topologi.com/2005/Diff-X", local:"ins"). Expected elements are <{http://schemas.openxmlformats.org/wordprocessingml/2006/main}subDoc>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sdt>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}del>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}dir>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pPr>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMathPara>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFrom>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}smartTag>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}hyperlink>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeStart>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMath>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXml>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ins>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bdo>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveTo>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fldSimple>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}proofErr>


The xml:
<?xml version="1.0" encoding="utf-8"?><w:body xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:dfx="http://www.topologi.com/2005/Diff-X" xmlns:del="http://www.topologi.com/2005/Diff-X/Delete" xmlns:ins="http://www.topologi.com/2005/Diff-X/Insert" xmlns:cdr="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing" xmlns:odi="http://opendope.org/components" xmlns:odq="http://opendope.org/questions" xmlns:pvml="urn:schemas-microsoft-com:office:powerpoint" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:xvml="urn:schemas-microsoft-com:office:excel" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:oda="http://opendope.org/answers" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:cppr="http://schemas.microsoft.com/office/2006/coverPageProps" xmlns:comp="http://schemas.openxmlformats.org/drawingml/2006/compatibility" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:wetp="http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11" xmlns:odx="http://opendope.org/xpaths" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy" xmlns:we="http://schemas.microsoft.com/office/webextensions/webextension/2010/11" xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart" xmlns:odc="http://opendope.org/conditions" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main">
<w:p w:rsidR="00CC3B88" ins:rsidR="true" w:rsidRDefault="00AA362D">
<w:r xmlns:xalan="http://xml.apache.org/xalan" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:ins="http://www.topologi.com/2005/Diff-X">
<w:t xml:space="preserve">This is sample </w:t>
</w:r>
<dfx:ins>
<w:r xmlns:xalan="http://xml.apache.org/xalan" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:ins="http://www.topologi.com/2005/Diff-X">
<w:t xml:space="preserve">doc</w:t>
</w:r>
</dfx:ins>
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<dfx:del>
<w:r xmlns:xalan="http://xml.apache.org/xalan" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:ins="http://www.topologi.com/2005/Diff-X">
<w:t xml:space="preserve">doc</w:t>
</w:r>
</dfx:del>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:sectPr w:rsidR="00CC3B88" ins:rsidR="true">
<w:pgSz w:h="15840" w:w="12240"/>
<w:pgMar w:bottom="1440" w:footer="720" w:gutter="0" w:header="720" w:left="1440" w:right="1440" w:top="1440"/>
<w:cols w:space="720"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>

Re: Compare documents failing.

PostPosted: Tue Feb 06, 2018 8:41 pm
by jason
The dfx namespaces should be gone before XmlUtils.unmarshalString is invoked.

That's the job of XSLT:

Code: Select all
         Source xsltSource = new StreamSource(org.docx4j.utils.ResourceUtils
               .getResource("org/docx4j/diff/diffx2wml.xslt"));
         xsltDiffx2Wml = XmlUtils.getTransformerTemplate(xsltSource);


Try DIVIDE_AND_CONQUER = true. The other might not be invoking diffx2wml.xslt?

Re: Compare documents failing.

PostPosted: Wed Feb 07, 2018 1:56 am
by Mark S
I have run both paths and the dfx name spaces remain. Is there any params I'm missing to run the CompareDocuments example without edits?

i do see printing
"invoking xsltDiffx2Wml"
and i have debugged thru and do see it loading the file.

Re: Compare documents failing.

PostPosted: Wed Feb 07, 2018 7:42 am
by jason
https://github.com/plutext/docx4j/commi ... 096549cd00 helps.

I'm surprised / not sure why those elements weren't handled before, but it is fair to say the differencing part of the code base is not used so much.

Just curious: are your documents edited in Word, such that they have rsids? I've been working on an rsid-based comparison tool recently, which looks good so far.

Re: Compare documents failing.

PostPosted: Wed Feb 07, 2018 9:03 am
by Mark S
That helped things a bit. Working for inserts now. Deletions are still a bit off its producing

<w:del xmlns:xalan="http://xml.apache.org/xalan" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:ins="http://www.topologi.com/2005/Diff-X" w:date="2009-03-11T17:57:00Z" w:author="someone" w:id="1">
<w:r>
<w:t xml:space="preserve">doc</w:t>
</w:r>
</w:del>

where i think <w:t xml:space="preserve">doc</w:t> should be delText? I see it there in the xslt but doesn't seem to be respecting it.

Yes all the edits I am working with will be originating in word itself.
Thank you for your help!

Re: Compare documents failing.

PostPosted: Wed Feb 07, 2018 6:50 pm
by jason
For the examples I tested it on, I got something like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
        <w:del xmlns:xalan="http://xml.apache.org/xalan" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" w:date="2009-03-11T17:57:00Z" w:author="someone" w:id="6">
            <w:r>
                <w:delText>para</w:delText>
            </w:r>
        </w:del>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Do you have some short documents you can post which exhibit the issue?

Re: Compare documents failing.

PostPosted: Thu Feb 08, 2018 12:41 am
by Mark S
Result:

<?xml version="1.0" encoding="utf-8"?><w:body xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:dfx="http://www.topologi.com/2005/Diff-X" xmlns:del="http://www.topologi.com/2005/Diff-X/Delete" xmlns:ins="http://www.topologi.com/2005/Diff-X/Insert" xmlns:cdr="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing" xmlns:odi="http://opendope.org/components" xmlns:odq="http://opendope.org/questions" xmlns:pvml="urn:schemas-microsoft-com:office:powerpoint" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:xvml="urn:schemas-microsoft-com:office:excel" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:oda="http://opendope.org/answers" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:cppr="http://schemas.microsoft.com/office/2006/coverPageProps" xmlns:comp="http://schemas.openxmlformats.org/drawingml/2006/compatibility" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:wetp="http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11" xmlns:odx="http://opendope.org/xpaths" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy" xmlns:we="http://schemas.microsoft.com/office/webextensions/webextension/2010/11" xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart" xmlns:odc="http://opendope.org/conditions" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main">
<w:p w:rsidR="003A5001" ins:rsidR="true" w:rsidRDefault="00AA362D">
<w:r xmlns:xalan="http://xml.apache.org/xalan" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:ins="http://www.topologi.com/2005/Diff-X">
<w:t xml:space="preserve">This is sample </w:t>
</w:r>
<w:del xmlns:xalan="http://xml.apache.org/xalan" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:ins="http://www.topologi.com/2005/Diff-X" w:date="2009-03-11T17:57:00Z" w:author="someone" w:id="1">
<w:r>
<w:t xml:space="preserve">doc</w:t>
</w:r>
</w:del>
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:sectPr w:rsidR="003A5001" ins:rsidR="true">
<w:pgSz w:h="15840" w:w="12240"/>
<w:pgMar w:bottom="1440" w:footer="720" w:gutter="0" w:header="720" w:left="1440" w:right="1440" w:top="1440"/>
<w:cols w:space="720"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>

Re: Compare documents failing.

PostPosted: Thu Feb 08, 2018 7:54 am
by jason
Hmmm, the input to the XSLT in this case is:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:p
       w:rsidR="003A5001"
       ins:rsidR="true"
       del:rsidR="00CC3B88"
       w:rsidRDefault="00AA362D">
        <w:r>
            <w:t
               xml:space="preserve"
               ins:space="true">This is sample <dfx:del>doc</dfx:del></w:t>
        </w:r>
    </w:p>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


That's a bit tricky (dfx:del in w:t)... stay tuned...

Re: Compare documents failing.

PostPosted: Thu Feb 08, 2018 6:41 pm
by jason
Please try https://github.com/plutext/docx4j/commi ... df10a0e0af

ps I see now that diffx sometimes writes the dfx namespace and sometimes doesn't. The old code handled the no-namespace case, and yesterday we added code to handle the namespace case. In this commit, they are bundled into common templates

Re: Compare documents failing.

PostPosted: Sat Feb 10, 2018 2:09 am
by Mark S
Thanks jason this certainly helped! I'll let you know if I come across anything else. As this is a great feature

Re: Compare documents failing.

PostPosted: Wed Feb 28, 2018 4:16 am
by sdeal
I'm having a similar issue with comparing documents. Specifically, I've observed that documents with VML shapes are not being parsed correctly. See this stack trace:

Code: Select all
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,4617]
Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#AttributePrefixUnbound?v:rect&o:spid&o
   at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596)
   at org.docx4j.diff.Differencer.combineAdjacent(Differencer.java:1251)
   at org.docx4j.diff.Differencer.toWML(Differencer.java:431)
   at org.docx4j.diff.Differencer.diffWorker(Differencer.java:334)
   at org.docx4j.diff.Differencer.diff(Differencer.java:302)
   at org.docx4j.samples.CompareDocuments.main(CompareDocuments.java:121)
java.lang.NullPointerException
   at java.io.StringReader.<init>(StringReader.java:50)
   at org.docx4j.diff.Differencer.toWML(Differencer.java:440)
   at org.docx4j.diff.Differencer.diffWorker(Differencer.java:334)
   at org.docx4j.diff.Differencer.diff(Differencer.java:302)
   at org.docx4j.samples.CompareDocuments.main(CompareDocuments.java:121)


I am not terribly familiar with XSLT, but I have tried adding the "v" and "o" namespaces to diffx2wml.xslt, and tried adding <xml:template match="v:*"/>, neither of which have helped. Am I on the right track in thinking this is an issue with the XSLT? I would be fine with removing the shapes if they can't be handled correctly, but I would like to be able to compare these documents without the operation failing. Let me know if you need more information. Thanks in advance!

(Also, sorry for hijacking this thread, but I figured that my issue is similar enough to the original issue here. If you'd rather I create a new thread, I can do that.)

Re: Compare documents failing.

PostPosted: Wed Feb 28, 2018 8:58 pm
by jason
Should be straightforward to fix, but it would be helpful if you could attach sample documents exhibiting the issue. thanks.

Re: Compare documents failing.

PostPosted: Thu Mar 01, 2018 2:49 am
by sdeal
Here are the two files I'm currently using. In particular, the "Test shape.docx" file seems to be causing the issue.

Re: Compare documents failing.

PostPosted: Thu Mar 01, 2018 11:20 am
by jason
Thanks for the test docx. Please see now https://github.com/plutext/docx4j/commi ... 132ef321a9
where I've added a workaround.

It'd be nice to have some time to figure out the root problem here...

This will be in a nightly build tomorrow.

Re: Compare documents failing.

PostPosted: Fri Mar 02, 2018 2:52 am
by sdeal
Thanks for the fix, the CompareDocuments operation completes without error now. However, I'm getting an error when I try to open the new file: "We're sorry. We can't open OUT_CompareDocuments.docx because we found a problem with its contents." The details Word gives are "An incorrect text node was used. Location: Part: /word/document.xml, Line: 0, Column: 0". Going through the prompts to have Word attempt to recover the file ends up showing the document, and everything looks fine once I get there.

This happens with the same files that I uploaded before, though it also happens with files that I'm pretty sure were working before. I don't think it's this latest fix you made that's causing this - I tried commenting out that latest code in Differencer.java and the problem persists.

Re: Compare documents failing.

PostPosted: Thu Mar 08, 2018 7:33 am
by sdeal
An update on my progress to get this working. I went back to the release tag of docx4j 3.3.6 and added your most recent code to Differencer.java, and I no longer have the issue where the document is not openable. However, I'm having different problems when I am trying to run this code in my deployment environment (Oracle WebCenter Content 12c, using WebLogic Server). First, I had this error:

Code: Select all
javax.xml.transform.TransformerException: java.lang.NoSuchMethodException: For extension function, could not find method static org.docx4j.diff.Differencer.registerRelationship([ExpressionContext,] #UNKNOWN (org.docx4j.diff.Differencer), #UNKNOWN (org.docx4j.openpackaging.parts.relationships.RelationshipsPart), #STRING, #STRING).
at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:422)
at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:440)
at org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:222)
at org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:475)
at org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:208)
at org.apache.xpath.XPath.execute(XPath.java:337)
at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:280)
at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:248)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:132)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2402)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2272)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1358)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:711)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1275)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1253)
at org.docx4j.XmlUtils.transform(XmlUtils.java:1367)
at org.docx4j.diff.Differencer.transformDiffxOutputToWml(Differencer.java:490)
at org.docx4j.diff.Differencer.toWML(Differencer.java:447)
at org.docx4j.diff.Differencer.diffWorker(Differencer.java:334)
at org.docx4j.diff.Differencer.diff(Differencer.java:302)


The call to Differencer.diff is set up the same as it is in the CompareDocuments example with DIVIDE_AND_CONQUER = false. This appears to be stemming from this section in diffx2wml.xslt, which appears multiple times:

Code: Select all
<xsl:variable name="dummy" select="java:org.docx4j.diff.Differencer.registerRelationship($Differencer, $docPartRelsLeft, $oldid, $newid)" />


The calls to java:org.docx4j.diff.Differencer.log() work fine, and I've double-checked the method definition in Differencer.java and it seems correct. I tried commenting out all instances of the above XSLT code, which caused another error to appear:

Code: Select all
unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"docGrid"). Expected elements are <{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ins>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}p>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tbl>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}proofErr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}del>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sdt>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMathPara>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveTo>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}altChunk>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMath>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFrom>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXml>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sectPr>


I tried adding a line <xsl:template match="w:docGrid" /> to remove that element, but that caused the resulting .docx file to be unopenable by Word. Any insights to any of these errors? I've been using the same two documents that I linked before. Again, I greatly appreciate all of your help!

Re: Compare documents failing.

PostPosted: Thu Mar 08, 2018 4:56 pm
by jason
Do you have Xalan on your classpath?

Re: Compare documents failing.

PostPosted: Fri Mar 09, 2018 1:25 am
by sdeal
I'm 99% sure that I do. Though it took some non-standard setup to get xalan on the classpath (as compared to what is normally done for components in WebCenter) so I would say it's possible that it still isn't set up correctly.