Problem: display values from nested XML file

Hello,

Is it possible with Jasperassistant to display values from a nested XML file (XML datasource)?

I can set the query from the report to “/main/groups/group” to select “number” (from a group). But the problem is when I want to display the amount (from element) in the same report. Only the first value is visible in the report.

Are there any examples for this (I already looked at the Nortwind example, it’s only 2 deep). How can I resolve this?


Thanks in advance,

Rob





Example XML file I used:

<main>
<groups>
<group>
<number>1</number>
<post>
<number>98</number>
<element>
<amount>5</amount>
</element>
<element>
<amount>6</amount>
</element>
<element>
<amount>7</amount>
</element>
</post>
</group>
<group>
<number>2</number>
<post>
<number>101</number>
<element>
<amount>65</amount>
</element>
<element>
<amount>66</amount>
</element>
<element>
<amount>67</amount>
</element>
</post>
</group>
</groups>
</main>
Yep.

You need to define your DataSource (as you've done) like:
/main/groups/group
which translates to...
<queryString language="xPath">
<![CDATA[/name/groups/group]]>
</queryString>


Then define your field description as:
post/number
or
post/element/amount
which translates into...
<field name="NumberOfPosts" class="java.lang.String">
<fieldDescription><![CDATA[post/element/amount]]></fieldDescription>
</field>


The tricky bit is, it will only show thr FIRST amount, to get it to iterate/loop over each branch you need to make a sub report. I just discovered how to do this too. :)

There is a sample subreport that comes with JasperReports, check it out for details.
This topic is archived Other recent topics