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

Free Support Forum - aspose.com

Xml and ReportingEngine


I have the need to build a word doc, using the ReportingEngine where xml will be inserted in 4 word tables within the document

XML Example


The generation of the xml may not always contain of the rows for the 4 tables

My code is a follows:

        // build the word template path
        var wordTemplate = Path.Combine(_templatePath, WordTemplateXmlRenderResultsDocx);

        // load the template
        var document = 
            new Aspose.Words.Document(wordTemplate);

        var xmlNodeReader = new XmlNodeReader(_xmlDocument);
        var dataSet = new System.Data.DataSet();

        // build the report
        var engine = new Aspose.Words.Reporting.ReportingEngine();
        engine.BuildReport(document, dataSet);

When using something like

<<foreach [a in Results]>>
<<foreach [b in a.Table1]>>
<<foreach [c in b.Rows]>>


I have no issue

However if I try the following

<<foreach [a in Results]>>
<<foreach [b in a.Table2]>>
<<foreach [c in b.Rows]>>


When there is no xml the ReportingEngine exception as there will be no table in dataSet

Is there a way to conditional check inside the word doc using the ReportingEngine marked for the table existance



Thanks for your inquiry. You can use conditional block to achieve your requirement. Please refer to the following article:
Using Conditional Blocks

Please use the conditional block as shown below. Hope this helps you.

<<foreach [a in Results]>>
<<if [a.Table2 != “”]>>
<<foreach [b in a.Table2]>><</foreach>>
<<foreach [b in a.Table1]>>
<<foreach [c in b.Rows]>>Test<</foreach>><</foreach>>

Best Regards,
Tahir Manzoor


The suggestion has not worked I get the following exception

Message: An error has been encountered at the end of expression 'a.Table2 != '. Can not get the value of member ‘Table2’ on type ‘System.Data.DataRow’.

Any other ideas?

In addition is it possible to call BuildReport multiple times on the same document with different objects e,g

        engine.BuildReport(document, dataSet1);
        engine.BuildReport(document, dataSet2);


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Your XML datasource.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

Best Regards,
Tahir Manzoor


I will produce what you have asked for and send them next week