We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to use TableStart and TableEnd in Word correctly (Nested XML)

Im trying to create a document from XML, which works quite fine for data, which is taken from the first level (root) of the XML. So now i need to take data from multiple node-levels in the XML, which is done with

{ MERGEFIELD TableStart:2ndLevelNode }
...my Word code takes items from the 2nd level node of the XML here (works)
{ MERGEFIELD TableEnd:2ndLevelNode }

in simpler constructs we had before.

For “deeper” levels in the XML we did it like that so far (simple nesting):

{ MERGEFIELD TableStart:2ndLevelNode }{ MERGEFIELD TableStart:3rdLevelNode }
...my Word code takes items from the 3rd level node of the XML here (works)
{ MERGEFIELD TableEnd:3rdLevelNode }{ MERGEFIELD TableEnd:2ndLevelNode }

We face the situation, that we have to refer to XML with multiple sublevels (5 levels and more), where “nesting” shown above would create a lot of unnecessary mergefields to retrieve maybe just one value from an XML-tag von 5th or 6th level of the XML.

Question: Can this be done without “nesting” all the levels of the XML via TableStart/TableEnd? Maybe by specifying the the whole path of levels in one TableStart / TableEnd tag?

Kinda like that:

{ MERGEFIELD TableStart:2ndLevelNode/3rdLevelNode/4thLevelNode }
...my Word code takes items from 4th level of the xml...
{ MERGEFIELD TableEnd:2ndLevelNode/3rdLevelNode/4thLevelNode }

Or can i alternatively look up the exact syntax i can use for TableStart / TableEnd somewhere, i did not find yet?

Thanks a lot for your help.

@KaeseSemmel

Unfortunately, there is no other way to do this using Mail Merge.

However, using of LINQ Reporting Engine would provide a more concise template syntax for this. Please refer to the following articles related to the engine:

In your scenario, in a template, you can use either nested foreach tags or a single foreach tag applying SelectMany several times in the tag’s expression. For more details on SelectMany, please check Enumeration Extension Methods.