Search code examples
docx4j

Creating copy of org.docx4j.wml.P;


In my project one of the requirement is to extract group of P's(call it block). I want to repeat this block n number of times in output document. P in the block contains some dynamic data which changes block by block.

I want to make copies of original P's so that I can add dynamic data into them and prepare a block.

P newP= Context.getWmlObjectFactory().createP();
newP = oldP;

However here, creating P and assigning old P to it assigns only reference of old P. How can I create a new P which will be similar to old P & still independent of it?


Solution

  • Use XmlUtils deepCopy method, at https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/XmlUtils.java#L1014