Search code examples
javadocx4jcustom-properties

How to remove custom properties in docx4j


It is possible to add custom properties in docx4j like this:

final DocPropsCustomPart customPart = getDocPropsCustomPart();
final Properties customProperties = customPart.getJaxbElement();
...
customProperties.getProperty().add(newProperty);

But how can I remove a property that is already set?


Solution

  • getProperty() returns List.

    As per the JavaDoc, this accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object.

    That approach is common across docx4j.

    So you can just remove the Property object from the list.