Question

I'm using iReport and I need to create a sub-report using a XML DataSource.

I will have only one XML for the hole report. Something like this:

<question>
  <text>What do you think about SO?</text>
  <options>
    <option>Like it</option>
    <option>Really like it</option>
    <option>Love it</option>
  </options>
</question>

The main report will have it's detail linked to the questions, each question will have many options. Each sub-report must be linked to the options for the question... Well master-detail.

All that I could find with some googling was using SQL, I want to use XPath.

Was it helpful?

Solution

Take a look at the JRXmlDataSource JavaDoc. There are example that show how it's done.

OTHER TIPS

Create your subreport as a report first using the xpath. Then create a subreport element in the parent report and link the subreport to the parent report. below is a sample subreport element:

<subreport>
    <reportElement x="0" y="20" width="555" height="100"/>
    <subreportParameter name="XML_DATE_PATTERN">
        <subreportParameterExpression><![CDATA[$P{XML_DATE_PATTERN}]]></subreportParameterExpression>
    </subreportParameter>
    <subreportParameter name="XML_DATA_DOCUMENT">
        <subreportParameterExpression><![CDATA[$P{XML_DATA_DOCUMENT}]]></subreportParameterExpression>
    </subreportParameter>
    <subreportParameter name="XML_LOCALE">
        <subreportParameterExpression><![CDATA[$P{XML_LOCALE}]]></subreportParameterExpression>
    </subreportParameter>
    <subreportParameter name="XML_NUMBER_PATTERN">
        <subreportParameterExpression><![CDATA[$P{XML_NUMBER_PATTERN}]]></subreportParameterExpression>
    </subreportParameter>
    <subreportParameter name="XML_TIME_ZONE">
        <expressionistic><![CDATA[$P{XML_TIME_ZONE}]]></subreportParameterExpression>
    </subreportParameter>
    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
    <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIRECTORY} + "PS_Product_Match.jasper"]]></subreportExpression>
</subreport>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top