I have a strange problem with Jasper Report and XML data sources. I have two reports that works great inside iReport (a preview shows all correct data), but when I run the report with JasperRunManager.runReportToPdfFile, the values show up as null. Funny thing is that one of the two reports have sub reports, and in the sub reports, everything shows up correctly!
I'm using XPath with a query like this:
<queryString language="xPath">
<![CDATA[/rosterArray/list/studentRoster]]>
</queryString>
and I only have one field:
<field name="studentName" class="java.lang.String">
<fieldDescription><![CDATA[studentName]]></fieldDescription>
</field>
And display it:
<detail>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="10" y="6" width="188" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{studentName}]]></textFieldExpression>
</textField>
</band>
</detail>
XML looks like this:
<rosterArray>
<list>
<studentRoster>
<studentName>Robert, Pascal</studentName>
</studentRoster>
</list>
</rosterArray>
And the code to create the generated report:
File xmlFileName = new File(xmlDSFileName());
JRXmlDataSource xmlDS = new JRXmlDataSource(xmlFileName);
xmlDS.setDatePattern("yyyy-mm-dd HH:mm:ss.S z");
File destFile = File.createTempFile(compiledReportName, ".pdf");
String inputFileName = PathUtilities.pathToReport(compiledReportName);
JasperRunManager.runReportToPdfFile(inputFileName, destFile.getPath(), parameters, dataSource);