Using Aspose Words for Java 14.3
I have been using the IMailMergeDataSource interface to merge XML data into a Word template to ultimately create a PDF. This is using the mail merge with regions. I started with the example from https://docs.aspose.com/words/java/mail-merge-with-xml-data-source/. For the most part, my implementation mirrors the example with the exception of just a couple of items. For most simple XML data, I have no problem merging the data into the template document, however, I have run into some problems when attempting to get child data elements (child data sources).
From the extensive testing I’ve done with multiple XML documents, I’ve found that XML child elements do not appear to be considered child elements for the mail merge engine if they have a text node contained within the element. Let me try to describe this. For the XML fragment below, in the middle of the XML document is para_line_data which contains repeating group text data in a para_line element. The template document is configured to have . When generating the PDF, only the first para_line is printed.
…
Line data
additional data
…
The only way I could get a child element to be considered a child element to output multiple lines is to wrap the real content in another unnecessary element. Adding the para_line_row to the XML and adding a TableStart/End for para_line_row around para_line in the template document, the data actually printed as expected.
Line data
additional data
While I can alter XML in some cases, I have some situations where I will not be allowed to alter the XML. As a result, I am looking for ways to define the IMailMergeDataSource implementation such that I can support both XML configurations (with or without the unnecessary para_line_row element). I have gotten the org.w3c.dom.Node and interrogated it upon creation of the IMailMergeDataSource impl. I found the proper count of child elements during creation, but found that subsequent records were never processed. It seems as if the IMailMergeDataSource interface should have additional methods to use as callbacks to help determine whether a Node or a NodeList is being return. Or something needs to be defined differently in the moveNext method to get the next element. Can anyone help with this situation?
I have included examples of both implementations as well as output from both to help describe the situation. The AsposeMergeTest class only needs to have configurations set for location, license file, and the input and output files. See both PDFs for the described behavior.
I have searched all over the Aspose site for additional details on how the mail merge engine works (especially with XML), but have found very very little. It’s very hard to decipher when the callbacks to the IMailMergeDataSource occur and for what condition in the XML. There are no API documents since the classes are encrypted. It’s all a black box, which doesn’t have enough documentation.