我对Jasper报告和XML数据源有一个奇怪的问题。我有两个在iReport中运行良好的报告(预览显示了所有正确的数据),但是当我使用JasperRunManager.runReportToPdfFile运行报告时,值显示为null。有趣的是,两个报告中的一个有子报告,并且在子报告中,所有内容都正确显示!
我使用XPath进行如下查询:
<queryString language="xPath">
<![CDATA[/rosterArray/list/studentRoster]]>
</queryString>我只有一个字段:
<field name="studentName" class="java.lang.String">
<fieldDescription><![CDATA[studentName]]></fieldDescription>
</field>并显示出来:
<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看起来像这样:
<rosterArray>
<list>
<studentRoster>
<studentName>Robert, Pascal</studentName>
</studentRoster>
</list>
</rosterArray>以及用于创建生成的报告的代码:
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);发布于 2014-03-20 18:06:22
在创建JRXmlDataSource对象时,必须添加querystring标记中定义的xpath select表达式。在您的情况下,它应该是:
JRXmlDataSource xmlDS = new JRXmlDataSource(xmlFileName, "/rosterArray/list/studentRoster");致以问候。
https://stackoverflow.com/questions/7903113
复制相似问题