'How to export XML format in Jasper Reports
I want to export data in xml format which needs to look like this using jasper, I downloaded the jaspersoft studio but there only pdf and csv formats available in it.
<List>
<item>
<id>1</id>
<name>Sandeep</name>
<oraganization>Data Matrix</oraganization>
<designation>Front-end Developer</designation>
<salary>20000</salary>
</item>
<item>
<id>2</id>
<name>Prince</name>
<oraganization>Genpact</oraganization>
<designation>Consultant</designation>
<salary>40000</salary>
</item>
<item>
<id>3</id>
<name>Gaurav</name>
<oraganization>Silver Touch </oraganization>
<designation>Sr. Java Engineer</designation>
<salary>47000</salary>
</item>
<item>
<id>4</id>
<name>Abhinav</name>
<oraganization>Akal Info Sys</oraganization>
<designation>CTO</designation>
<salary>700000</salary>
</item>
</List>
I'm using spring -boot application and Jaspher to export the xml format The file employee-rpt.jrxml is template for pdf format and i'm trying to use same template to import data and export it in XML format
private List<Employee> empList = Arrays.asList(
new Employee(1, "Sandeep", "Data Matrix", "Front-end Developer", 20000),
new Employee(2, "Prince", "Genpact", "Consultant", 40000),
new Employee(3, "Gaurav", "Silver Touch ", "Sr. Java Engineer", 47000),
new Employee(4, "Abhinav", "Akal Info Sys", "CTO", 700000));
public String generateReportXML() {
try {
String reportPath = "C:\\Temp\\Report";
// Compile the Jasper report from .jrxml to .japser
JasperReport jasperReport = JasperCompileManager.compileReport(reportPath + "\\employee-rpt.jrxml");
// Get your data source
JRBeanCollectionDataSource jrBeanCollectionDataSource = new JRBeanCollectionDataSource(empList);
// Add parameters
Map<String, Object> parameters = new HashMap<>();
parameters.put("createdBy", "Websparrow.org");
// Fill the report
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,
jrBeanCollectionDataSource);
// Export the report to a XML file
String report=JasperExportManager.exportReportToXml(jasperPrint);
System.out.println("Done");
return report;
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|