Mail merge document template validation

Hi,
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,
Michal

Hi

Thanks for your request. there are few simple rules:

  1. 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.
  2. Mail merge regions can be nested inside each other.
  3. Mail merge regions should be well formed (there is always a pair of matching TableStart and TableEnd with the same table name).
  4. End of one region cannot follow by start of another region. i.e. the following construction is incorrect:

<TableStart:Region_2>
<TableEnd:Region_1>
Hope this helps.
Best regards,