简体   繁体   English

报表中的XML数据源不起作用

[英]XML Datasource in report is not working

I want to compile a .JRXML file with an XML Datasource in Java. 我想用Java中的XML数据源编译.JRXML文件。 It works perfectly within iReport . 它可以在iReport中完美运行。 In Java, it does not work. 在Java中,它不起作用。

When I set the main query language to 'xpath', the report is generated, but with no xml data in it. 当我将主要查询语言设置为“ xpath”时,将生成报告,但其中没有xml数据。

With 'xpath2' as the main query language, I get an error "No query executer factory registered for the 'xpath2' language" and the report is not being generated. 使用'xpath2'作为主要查询语言时,出现错误“没有为'xpath2'语言注册工厂查询执行器”,并且未生成报告。

It doesn't even work with the simplest report you can think of. 它甚至无法与您想到的最简单的报告一起使用。

What I've tried so far: 到目前为止,我已经尝试过:

  • Checked for the following line in jasperreports.properties: net.sf.jasperreports.query.executer.factory.xpath2=com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory 在jasperreports.properties中检查以下行:net.sf.jasperreports.query.executer.factory.xpath2 = com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory
  • Checked for the .jar file "jasperreports-extensions-3.5.3.jar" in my applications classpath 在我的应用程序类路径中检查了.jar文件“ jasperreports-extensions-3.5.3.jar”
  • Added this line to my Java code: jasperReport.setProperty("net.sf.jasperreports.query.executer.factory.xpath2", "com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory"); 将此行添加到我的Java代码中:jasperReport.setProperty(“ net.sf.jasperreports.query.executer.factory.xpath2”,“ com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory”);
  • Set the XML Datasource in Java: org.w3c.dom.Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(args[2])); 在Java中设置XML数据源:org.w3c.dom.Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(args [2])); params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document); params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT,文档);

My report generation code: 我的报告生成代码:

JasperReport jasperReport = JasperCompileManager.compileReport(args[0]);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint, args[1]);

After adding jasper-compiler-jdt-5.5.23.jar to my Java Build Path, I got rid of the xpath2 error. 将jasper-compiler-jdt-5.5.23.jar添加到Java构建路径后,我摆脱了xpath2错误。 The report is generated, but with no data source. 报告已生成,但没有数据源。

It now works with an xpath datasource. 现在,它可以与xpath数据源一起使用。 I created the datasource in my Java application instead of passing the XML_URL. 我在Java应用程序中创建了数据源,而不是传递XML_URL。 It's not perfect, but a good workaround. 这不是完美的方法,但是很好的解决方法。 This is the code I used: 这是我使用的代码:

org.w3c.dom.Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream("/file/location.xml"));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JRXmlDataSource(document, "/xpath"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM