How to MailMerge complicated table structure with XML

Hi there experts.

I need to make a word document out of XML (please see the attachment xmlExample.xml), and the output should be like in the attached file (tableExample.docx).

The only sollution I can think of at theis moment, is the forbidden way of using MERGEFIELD TableEnd:MyTable in the subsequent row. (Please look at the enclosed file template.docx)

Any ideas how I can accomplish this?

Cheers,
Lucian.

Hi Lucian,

Thanks for your inquiry. Please check the simple rules when marking a region from here:
https://docs.aspose.com/words/java/types-of-mail-merge-operations/

I have modified your template document according to your shared XML data source and desired output. I have highlighted the regions in template document for your kind reference. Hope this helps you.

Moreover, please check following documentation link about ‘How to mail merge from Xml’.
https://docs.aspose.com/words/java/mail-merge-with-xml-data-source/

Document doc = new Document(MyDir + "template_modified.docx");
javax.xml.parsers.DocumentBuilder db = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document xmlData = db.parse(MyDir + "xmlExample.xml");
doc.getMailMerge().executeWithRegions(new XmlMailMergeDataSet(xmlData));
doc.save(MyDir + "Out.docx");

Hey there Tahir!

Thank you very much for this. You saved me a lot of headache!
Would never have came up with the construct: table in row of another table.

Everything works as expected.

Thanks again!
Cheers,
Lucian.

Hi Lucian,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.