简体   繁体   中英

XML Datasource in report is not working

I want to compile a .JRXML file with an XML Datasource in Java. It works perfectly within iReport . In Java, it does not work.

When I set the main query language to 'xpath', the report is generated, but with no xml data in it.

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.

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
  • Checked for the .jar file "jasperreports-extensions-3.5.3.jar" in my applications classpath
  • Added this line to my Java code: 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])); params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, 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. The report is generated, but with no data source.

It now works with an xpath datasource. I created the datasource in my Java application instead of passing the 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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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