I\'m using docx4j to read contents of a word document.
The core.xml has a description
tag which I would like to modify in the documents I\'m reading.
See the sample DocProps.java at line 64 for how to fetch the core props part.
Then its something like:
JAXBElement<SimpleLiteral> desc = coreProps.getDescription();
SimpleLiteral literal = XmlUtils.unwrap(desc);
List<String> contents = literal.getContent();
Then modify that list. As is typical with JAXB, its a live list, so your changes will be made immediately to the in-mem representation of the document.
Or you could create a new JAXBElement<SimpleLiteral> desc2, then coreProps.setDescription(desc2). That's what you'd do for a docx which doesn't have a dc:description already:
org.docx4j.docProps.core.dc.elements.ObjectFactory dcFactory = new org.docx4j.docProps.core.dc.elements.ObjectFactory();
SimpleLiteral literal = dcFactory.createSimpleLiteral();
coreProps.setDescription(dcFactory.createDescription(literal));
List<String> contents = literal.getContent();
// populate contents ...
Then save the docx. The sample linked above does that.