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

Free Support Forum - aspose.com

Aspose words + Linq reporting engine + xml

Hi,
i’m trying to use the new possibility offered by dataSet.readXml in order to create a document using linq reporting engine from an xml file and would like to reference an inner attribute in the template.

…but

when i use this xml:

Potestá

and try to reference it in the template with

<<foreach [in iscrizionePdf]>>
<<[oggetto.testo]>>
<</foreach>>

comes this error:

java.lang.IllegalStateException: An error has been encountered at the end of expression ‘Oggetto.Testo]>’. Can not get the value of member ‘Testo’ on type ‘class asposewobfuscated.zzTJ’.

With mail merging it was ok to reference an inner attribute like i’ve made before. Is it a bug or am i making a mistake ?

I attach the source code, thank you very much.

Simone

Hi Simone,

Thanks for your inquiry. Please modify your xml and template syntax as shown below. This will fix the issue which you are facing. Please let us know if you have any more queries.

test 1
my test result 1

test 2
my test result 2

DataSet dataSet = new DataSet();
dataSet.readXml(MyDir + "in.xml");

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.writeln("<<foreach [s in iscrizionePdf]>>");
builder.writeln("<<[test]>>");
builder.writeln("<<foreach [in s.oggetto]>>");
builder.writeln("<<[testo]>>");
builder.writeln("<</foreach>>");
builder.writeln("<</foreach>>");

ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, dataSet);

doc.save(MyDir + "Out.docx");

Hi Tahir.

Linq is supposed to handle inner objects through the “.” operator as shown here https://docs.aspose.com/words/net/typical-templates/ in In-Table Master-Detail Template [Client.Name].

If i have to mix values of different objects the method you proposed becomes unusable.

For example, let’s think of this xml which contains 2 objects at the same level (identity and issue):

ABC

Simone
123

xxxx

If i want to put on the template “issue.title” between “identity.name” and “identity.id” it’s a mess…

i have to write something like this:
<<foreach [in identity]>><<[id]>><> <<foreach [in issue]>><<[title]>><> <<foreach [in identity]>><<[name]>><>

but it should work simply like this (“old” Mail Merge with XmlDataSet even can handle it this way)

<<[identity.id]>><<[issue.title]>><<[identity.name]>>

Hope to receive good news from you, thanks.

Simone

Hi Simone,

Thanks for your inquiry.

simone.padovan:

i have to write something like this:
<<foreach [in identity]>><<[id]>><> <<foreach [in issue]>><<[title]>><> <<foreach [in identity]>><<[name]>><>

Please note that old mail merge engine and new linq mail merge engine are different. In your scenario, you need to write the template as explained in my previous post.

To load xml in DataSet and perform mail merge operation is about ‘Working With Traditional Mail merge Data Sources’. Please read following links for your kind reference.
https://docs.aspose.com/words/net/composing-expressions/

Please note that there is no such class like DataSet in Java API which read the xml file. Aspose.Words for Java introduced this feature to load the xml in DataSet same as .NET does. Please check : https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/loading-a-dataset-from-xml

You are working with XML data source. So, you need to create the template as shown in my previous post.

simone.padovan:

but it should work simply like this (“old” Mail Merge with XmlDataSet even can handle it this way)
<<[identity.id]>><<[issue.title]>><<[identity.name]>>

The code example XmlDataSet implements IMailMergeDataSource interface. Implement this interface to allow mail merge from a custom data source, such as a list of objects. Master-detail data is also supported.

The XmlMailMergeDataTable handle one table at a time. The implementation of IMailMergeDataSource getChildDataSource handles this scenario (<<[identity.id]>><<[issue.title]>><<[identity.name]>>).

The
new Linq reporting engine is different from classic mail merge engine. Please note that the IMailMergeDataSource is not supported by LINQ Reporting Engine by design.

Hi Tahir, i understand, but i think it is so much usefull to reference an inner attribute without surrounding it with foreach statement.

Linq Reporting engine could try to retrieve the first occurance of the object ih this case…and all will work fine.

And please consider adding the conditional statement you added in linq to the old mail merge too, if i cannot jump to linq i’ll have to stay on mail merge and this feature is fundamental.

Thanks

Simone

Please take a look at the templates i attach…i have different objects in the xml, all to be displayed on the same page…i have to pollute foreach tag allover the template in order to let it work…

Hi Simone,

Thanks for sharing the detail. As you are dealing with a single data row, we suggest you to use first, single, or last LINQ extension methods. Please read about extension methods from here:
https://docs.aspose.com/words/java/appendix-a-enumeration-extension-methods/

You are using Java. So, for LINQ extension methods’ behavior, please read this MSDN link. Hope this help you.

Please check following code example and xml for your kind reference. Hope this helps you.

<?xml version="1.0" standalone="yes" ?>
<begin>
  <iscrizionePdf>
    <test>ABC</test>
    <identity>
       <name>Simone</name>
       <id>123</id>
    </identity>
    <issue>
       <title>xxxx</title>
    </issue>
  </iscrizionePdf>
</begin>
DataSet dataSet =         new     DataSet();
dataSet.readXml(        MyDir     + "in.xml");

Document doc = new Document();
DocumentBuilder builder = new        DocumentBuilder(doc)    

builder.writeln(        "<<foreach [s in iscrizionePdf]>>"    );
builder.writeln("<<[test]>>");
builder.writeln("<<[s.identity.first().name]>>");
builder.writeln("<<[s.identity.first().id]>>");
builder.writeln("<<[s.issue.first().title]>>");
builder.writeln("<</foreach>>");

ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, dataSet);

Thank u very much Tahir, that’s what i was asking for !
It’s certanly a much better solution.

Thanks one more for your time.

Simone

Hi Simone,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.