Xml and Linq Reporting Engine

Hi,

I am trying to use LINQ Reporting Engine, with datasource XML, but i have this error :
FAILED - An error has been encountered at the end of expression ‘id.dataInfrazione]>’. Can not get the value of member ‘dataInfrazione’ on type ‘class com.aspose.words.net.System.Data.DataRowCollection’.

This my xml :

<dati>
	<id nomefile="STDV10074974S2019" nr="620_22-07-2021_12-28-09-558" ordine_stampa="0">
		<template>template1</template>
		<DataInfrazione>24/07/2021</DataInfrazione>
	</id>
</dati>

and this is my code :

try
{
    var loadOptions = new LoadOptions();
    loadOptions.setLoadFormat(LoadFormat.DOCX);
    var destinationFile = destination + File.separator + filename.getName();

    // Carico il documento Aspose Words
    var doc = new Document(filename.toString(), loadOptions);

    // Setto la classe custom per il merge field
    final var mergeFieldCustom = new MergeFiledCustomTest();
    ReportingEngine engine = new ReportingEngine();

    doc.getMailMerge().setFieldMergingCallback(mergeFieldCustom);

    File dati = ResourceUtils.getFile("classpath:dati2.xml");

    DataSet ds = new DataSet();
    ds.readXml(dati.toPath().toString());
    engine.buildReport(doc, ds, "dati");

My template has only 1 row :

<<[id.dataInfrazione]>>

Where am I wrong ?

Thanks.

Samuele

@samuele.lucarini

Although there is a single id element in your XML data, DataSet still loads id as a data table. As per Working with DataTable Objects, a data table is processed as a collection of its rows by the engine, so id refers to all rows (although there is just one in fact) and you should refer to the first one in your template explicitly as follows:

<<[id.first().dataInfrazione]>>

Thanks for your response, that’s really helpful.

1 Like