JRXmlDataSource with queryString not writing

I have a problem with the XML data source for Jasper Reports. When I use the selectExpression constructor in JRXmlDataSource , everything works, but when I use queryString in .jrxml , I don't get any records.

working example:

 JRXmlDataSource ds2 = new JRXmlDataSource(new FileInputStream(dataSourceFile), "/pages/page"); 

does not work:

 JRXmlDataSource ds1 = new JRXmlDataSource(new FileInputStream(dataSourceFile)); <jasperReport> <queryString language="xPath"> <![CDATA[/pages/page]]> </queryString> ... </jasperReport> 

XML data:

 <?xml version="1.0" encoding="UTF-8"?> <pages> <page> <firstname>X</firstname> <lastname>Y</lastname> </page> <page> <firstname>Z</firstname> <lastname>V</lastname> </page> <page> <firstname>B</firstname> <lastname>S</lastname> </page> </pages> 
+4
source share
1 answer

I have found a solution. Instead of passing the XML data source to the JasperFillManager XML document can be passed to it, as shown below. Now XPath in <queryString language="xPath"> inside the .jrxml template .jrxml working on the submitted document and that is what I want.

 Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(dataSourceFile)); params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document); jasperPrint = JasperFillManager.fillReport(jasperReport, params); 
+6
source

Source: https://habr.com/ru/post/1399185/


All Articles