Jump to content

xml datasource for subreports


eiacob

Recommended Posts

Hi,

This is somehow related to some other topics, but I couldn't find an answer to my problem.

I have a single XML data source from which I want a master report and at least one subreport. Does anybody know if this is possible and how?

The XML sample is posted below. The outer <row> elements need to go into the main report, the inner <row> must go into the subreport(s). Is there any way to achive that? My main issue is that there is no way I can provide a datasource for the subreport. Initially I sent this to the subreport :

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource()

I found this was bad practice, but it was the only way I figured to do it (after reading javadocs). However, that does not work anymore if sorting is used: $P{REPORT_DATA_SOURCE} holds a reference to a ListOfArrayDataSource.

It is frustrating that I can easily get a reference to the <item> element that holds the inner <row> element, but there is  not much I can do with it in the subreport.

Any advice?

Thanks,

Emil

Code:
<row>  <item header="Code">$SITE-PREFIX$-C-12</item>  <item header="Use">Prevent</item>  <item header="Control">Control 1 Name</item>  <item header="SYSTEMRATING">4</item>  <item header="ENGINEERRATING">1</item>  <item header="DESIGNLEVEL">4</item>  <item header="ACTIONS">    <row>      <item header="ACTIONS.ACTIONCODE">$SITE-PREFIX$-A-5</item>      <item header="ACTIONS.PRIORITY">Low</item>      <item header="ACTIONS.COMPLETEBYDATE">2010-Oct-20</item>      <item header="ACTIONS.OVERDUE">82</item>      <item header="ACTIONS.STATUS">In-Progress</item>    </row>    <row>      <item header="ACTIONS.ACTIONCODE">$SITE-PREFIX$-A-5</item>      <item header="ACTIONS.PRIORITY">Low</item>      <item header="ACTIONS.COMPLETEBYDATE">2010-Oct-20</item>      <item header="ACTIONS.OVERDUE">82</item>      <item header="ACTIONS.STATUS">In-Progress</item>    </row>  </item></row>
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

In case somebody needs this, here is the solution I found:

Main Report:

- query: /row/item

- field pointing to the subtree to be send to subreport: $F{ACTIONS}=item[@header=ACTIONS]

- subreport datasource expression (for the current "record", it creates an appropriate XML data source for subreport): new net.sf.jasperreports.engine.data.JRXmlDataSource(net.sf.jasperreports.engine.util.JRXmlUtils.createDocument($F{ACTIONS}), "/item/row")

Subreport:

- query: /item/row

- define (sub)report fields as needed

 

Emil

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...