If you run the PartsList sample on your docx, you'll see the tree includes something like:
- Code: Select all
Part /word/document.xml [org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart] containing JaxbElement:org.docx4j.wml.Document
Part /customXml/item1.xml [org.docx4j.openpackaging.parts.CustomXmlDataStoragePart]
Part /customXml/itemProps1.xml [org.docx4j.openpackaging.parts.CustomXmlDataStoragePropertiesPart] containing JaxbElement:org.docx4j.customXmlProperties.DatastoreItem
You could delete item1.xml and add replace it with a new part of the same name, but if you did this, you'd have to reattach itemProps1.xml as well.
The easiest approach is leave the structure intact, ie to keep your existing item1.xml part, and just replace its data.
CustomXmlDataStoragePart has methods:
- Code: Select all
public void setData(CustomXmlDataStorage data)
public CustomXmlDataStorage getData() {
Use getData() to get the existing CustomXmlDataStorage, and then inject your data using either of:
- Code: Select all
public void setDocument(InputStream is) throws Docx4JException
public void setDocument( org.w3c.dom.Document doc )
(Or, if it suited you better, you could use:
- Code: Select all
public org.w3c.dom.Document getDocument() throws Docx4JException
and modify the existing document as you saw fit)
Let me know how you go.