Page 1 of 1

Invalid xml after template modification [SOLVED]

PostPosted: Thu Aug 09, 2018 8:49 pm
by mda
Hi there.
I have a docx template with several placeholders like ${name}, and I'm using docx4j for the replacement of the placeholders.
I found a code that works pretty well (you can find it in attach) but when I open the new file created in Microsoft word, I get this error message:
"The xml data is invalid according to the schema. Location: Part: /word/document.xml, Line:0, Column:0".
After that error message I get another message:
"Word found unreadable content. Do you want to recover the content of this document? If you trust the source of this document, click yes".
At this point if I click yes the document results correct, but all this messages are really annoying.

I'm new to docx manipulation and I don't know how to solve this problem.

Re: Invalid xml after template modification

PostPosted: Thu Aug 09, 2018 9:54 pm
by jason
Feel free to post your docx as saved from your code.

Or if it is sensitive, you can unzip and compare your word/document.xml to Word's repaired word/document.xml

There is a tool which makes it a bit easier to do this sort of comparison, you can Google for Microsoft OpenXML SDK.

Re: Invalid xml after template modification

PostPosted: Fri Aug 10, 2018 1:05 am
by mda
First of all thanks for your reply.
In the document.zip there are 3 files:
-documentTEMPLATE.xml -- the word/document.xml of the template
-documentBEFORE.xml -- the word/document.xml of the document generated from the template (the corrupted)
-documentAFTER.xml -- the word/document.xml after the recovery process.

Right now I can't post the document, I will change it a little to make it postable.

EDIT
attachment update. Now it contains another 2 documents:
-DocumentoCustodiaTemplate.docx -- the document template
-LatestDoc.docx -- the document generated from the java code (xml corrupted). Just ignore the "$" on the first line, I don't know why that one wasn't replaced.

Re: Invalid xml after template modification

PostPosted: Fri Aug 10, 2018 8:12 am
by jason
Looks like you are missing xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"

This was fixed in 3.3.5; suggest you upgrade to 6.0.1

Re: Invalid xml after template modification

PostPosted: Fri Aug 10, 2018 7:29 pm
by mda
jason wrote:Looks like you are missing xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"

This was fixed in 3.3.5; suggest you upgrade to 6.0.1


Yes, it works perfectly now :D .
Thank you very much for your availability ;)