my application allows a user to edit document templates that are used in mail-merge document generation. I’d like to validate the template after the user changed it to reject the invalid templates and prevent, for instance, the “Mail merge region ‘XXX’ is badly formed. TableStart and TableEnd should be in the same section, same table row or same table cell.” exception during the mail-merge process. Ideally I’d like to use the same code that Aspose.Words uses to validate the template. Could you provide this code here, is it possible? If not, could you describe the algorithm?
Thanks for your request. there are few simple rules:
- TableStart and TableEnd fields must have the same grandparent, i.e. they must be inside the same section in the document and if used inside a table, TableStart and TableEnd must be inside the same row in the table.
- Mail merge regions can be nested inside each other.
- Mail merge regions should be well formed (there is always a pair of matching TableStart and TableEnd with the same table name).
- End of one region cannot follow by start of another region. i.e. the following construction is incorrect:
Hope this helps.