3

I have been trying different things with content controls and docx4j. I added/removed couple of controls and now docx4j wont load the document anymore. Getting this error ar runtime.

org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships'

This statement from the 'Getting started' guide caught my eye.

There is a limitation however: the xpath expressions are evaluated against the XML document as it was when first opened in docx4j. You can update the associated XML document once only, by passing true into getJAXBNodesViaXPath. Updating it again (with current JAXB 2.1.x or 2.2.x) will cause an error.

I use docx4j nightly build from apr 2nd and I do use xpath. Could the error be because of this? If so, where does docx4j maintain this information?

Artin
  • 745
  • 1
  • 7
  • 14

1 Answers1

3

"Failed to add parts from relationships" means that some part (for example, the main document part) has a relationship to another part (for example, a header, footer, or image) that is missing (ie not actually present) in the package.

Turn debug level logging on for org.docx4j.openpackaging ought to tell you where the missing part is, and from that you can probably guess what code is breaking the docx.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Thanks for the response Jason. Yup. I guessed so too. But the wonder is that I created another docx from scratch and it had the same issue too. That was weird. So, can I safely assume that the error and the statement from the getting started guide are not related? – Artin Apr 04 '14 at 12:44
  • When you create the document from scratch, what are you doing? (eg adding images, a header etc) – JasonPlutext Apr 04 '14 at 20:27
  • I added 3 text and 1 image content controls. Using content control toolkit, set up the mapping. I tried something similar today. It didnt throw the exception but the output doc wouldnt save the bindings(on a different question). – Artin Apr 04 '14 at 21:13
  • ok well i guess we focus on http://stackoverflow.com/questions/22869070/wordprocessingmlpackage-save-not-saving-bindings-docx4j – JasonPlutext Apr 07 '14 at 08:46