Page 1 of 1

unexpected element

PostPosted: Sat Nov 20, 2010 3:27 am
by sri
Using: Docx4j 2.6.0

I am attempting to inject custom XML into an existing Word 2010 document. I have followed the example of http://dev.plutext.org/trac/docx4j/browser/trunk/docx4j/src/main/java/org/docx4j/samples/CreateDocxWithCustomXml.java (except that I starting with an existing document).

However what I end up with is a blank document. The resulting file is several orders of magnitude smaller that the starting template. Poring over the logs I noted numerous warnings of the form
Code: Select all
WARN handleEvent(JaxbValidationEventHandler.java:44) [ERROR] : unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"docDefaults")

I don't know much about the internals of Word and therefore am unable to interpret the meaning of the error/warning.

Can you help?

Re: Injecting custom XML results in a blank doc

PostPosted: Sat Nov 20, 2010 7:29 am
by jason
Are you able to send me your docx and code, either on list (zipped up), or by email?

Re: Word 2010: Injecting custom XML results in a blank doc

PostPosted: Sat Nov 20, 2010 8:39 am
by sri
Jason:
Wouldn't you know it. I just created a Maven project including just the files you need and it works in that project!

Aaaargh.

Now I have to figure out why it does not work in the actual project.

Thanks anyway

Sri

Re: Word 2010: Injecting custom XML results in a blank doc

PostPosted: Sat Nov 20, 2010 9:16 am
by sri
I found the problem.

My project has a dependency on JAXB -- outside of its reliance on Docx4J. However the version of JAXB I was using was 2.2.1. When I removed that dependency, Docx4J's dependency on JAXB kicked in -- and that is version 2.1.3. This made Docx4J happy. And for the record my other dependency on JAXB is content with version 2.1.3 as well.

So, all's well.

Sri

Re: Word 2010: Injecting custom XML results in a blank doc

PostPosted: Sat Nov 20, 2010 9:38 am
by jason
Great - glad you identified the problem.

That problem with old version of JAXB has cropped up before.

Renaming this topic, since it has nothing to do with custom xml per se :-)