Java 当数据源为XML时,报表中只生成一行
我正在尝试使用XML数据源生成报告。我的输入xml文件有4行。但JR引擎生成的报告只包含第1行 我有Java 当数据源为XML时,报表中只生成一行,java,xpath,jasper-reports,Java,Xpath,Jasper Reports,我正在尝试使用XML数据源生成报告。我的输入xml文件有4行。但JR引擎生成的报告只包含第1行 我有部分以获取数据 我的jrxml文件如下所示 我的输入XML是 <response id="1074200577"> <results id1="0" id2="0"> <field count="7556">one</field> <field count="7524">two</fiel
代码>部分以获取数据
我的jrxml文件如下所示
我的输入XML是
<response id="1074200577">
<results id1="0" id2="0">
<field count="7556">one</field>
<field count="7524">two</field>
<field count="7402">three</field>
<field count="7304">four</field>
</results>
</response>
一
二
三
四
我的Java客户端是
JasperCompileManager.compileReportToFile(inpuutjrxml, outputjasper);
JRXmlDataSource source = new JRXmlDataSource(new File(sourceFile));
HashMap<String, Object> params = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(outputjasper, params, source);
JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(pefoutput));
jaspecompilemanager.compileReportToFile(inpuutjrxml,outputjasper);
JRXmlDataSource source=新JRXmlDataSource(新文件(源文件));
HashMap params=新的HashMap();
JasperPrint JasperPrint=JasperFillManager.fillReport(outputjasper,params,source);
导出报告topdfstream(jasperPrint,新文件outputstream(pefoutput));
如何从输入xml中获取所有值
还有,如何获取的id值?
对于第一个xml行one
提供与“一”相同的数据。您可以尝试此查询(XPath):
本声明:
使用iReport
从iReport尝试的完整jrxml文件:
输入数据的结果将是(通过iReport中的预览):
注意:
我使用了iReport 5.2.0
使用Java代码
您应该将代码修改为:
JRXmlDataSource source = new JRXmlDataSource(new File(sourceFile), "/response/results/field");
HashMap<String, Object> params = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(outputjasper, params, source);
JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(pefoutput));
JRXmlDataSource source=newjrxmldatasource(新文件(sourceFile),“/response/results/field”);
HashMap params=新的HashMap();
JasperPrint JasperPrint=JasperFillManager.fillReport(outputjasper,params,source);
导出报告topdfstream(jasperPrint,新文件outputstream(pefoutput));
在本例中,我们使用的是构造函数。我们正在传递带有数据的查询
jrxml应该是:
如您所见,我已从模板中删除了queryString-我们正在用Java代码传递查询。您可以尝试此查询(XPath):
本声明:
使用iReport
从iReport尝试的完整jrxml文件:
输入数据的结果将是(通过iReport中的预览):
注意:
我使用了iReport 5.2.0
使用Java代码
您应该将代码修改为:
JRXmlDataSource source = new JRXmlDataSource(new File(sourceFile), "/response/results/field");
HashMap<String, Object> params = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(outputjasper, params, source);
JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(pefoutput));
JRXmlDataSource source=newjrxmldatasource(新文件(sourceFile),“/response/results/field”);
HashMap params=新的HashMap();
JasperPrint JasperPrint=JasperFillManager.fillReport(outputjasper,params,source);
导出报告topdfstream(jasperPrint,新文件outputstream(pefoutput));
在本例中,我们使用的是构造函数。我们正在传递带有数据的查询
jrxml应该是:
正如您所看到的,我已经从模板中删除了queryString—我们正在用Java代码传递查询。在我的情况下,我错误地将textField元素放在summary元素中。我可以通过将textField移到detail元素中来解决这个问题。在我的情况下,我错误地将textField元素放在summary元素中。我可以通过移动细节元素中的文本字段来解决这个问题。好的,child::text()仍然给我空值。@Count也给出了null。。看起来我这里还有其他问题。
这给了我一个7556
,但我仍然无法获取所有属性您是否将查询更改为/response/results/field
?是的。是我干的。但是没有LuckId您尝试使用我的模板?好的,child::text()仍然给我空值。@Count也给出了null。。看起来我这里还有其他问题。
这给了我一个7556
,但我仍然无法获取所有属性您是否将查询更改为/response/results/field
?是的。是我干的。但是没有运气你想用我的模板吗?
JRXmlDataSource source = new JRXmlDataSource(new File(sourceFile), "/response/results/field");
HashMap<String, Object> params = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(outputjasper, params, source);
JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(pefoutput));