0
votes

I have to use an XML as a data source in my report. My xml has multiple child tags with the same name(ex. author). Please refer the XML pasted below.

<BookStore>
<Book>
<title>History</title>
<author>Tom</author>
<copies>10;</copies>
<price>80</price>
</Book>

<Book>
<title>Basic Mathematics</title>
<author>Roy</author>
<author>Jon</author>
<copies>5</copies>
<price>100</price>
</Book>

<Book>
<title>Java</title>
<author>Harry</author>
<author>Potter</author>
<copies>6</copies>
<price>100</price>
</Book>
</BookStore>

I have added a XML data source and a dataset in my report. I have made the following mappings in my XML dataset.

Row mapping: /BookStore/Book and Column Mapping: Mapped all the child tags

In the data set, I am getting three records, one for each of the tag. But, the author column contains the value of only the first tag.For example, the second record contains only "Roy". The second author tag is not being recognised by the BIRT. I need to get both "Roy" & "Jon" from the second Book element. And, I need to get both "Harry" & "Potter" from the third Book element. Can you please let me know how to get all the values from tags with the same name into the dataset.

Appreciate your help. Please let me know how to design the XML dataset.

3

3 Answers

0
votes

In your data set you could make multiple columns such as author[1], author[2], author[3]. Then you could make a computed column that concatenates those columns together.

I do not think that XPath functions are supported in BIRT reports.

0
votes
public class ExportPDF {

    public static void main(String[] args) throws JRException {
        String sourceFileName = "E:/ireport/issueVoucher.jasper";

        String printFileName = null;

        JRXmlDataSource beanColDataSource = new JRXmlDataSource("E:/ireport/dbsource.xml","/root/data");


        Map<String, Object> parameters = new HashMap<String,Object>();
        parameters.put("reqNo", "33434");
        parameters.put("requestorName", "Shaan");
        parameters.put("empCode", "E03030");
        parameters.put("voucherNo", "E03030");
        parameters.put("issueDate", "E03030");
        parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, beanColDataSource);

        try {
            printFileName = JasperFillManager.fillReportToFile(sourceFileName, parameters, beanColDataSource);
            if (printFileName != null) {
                JasperExportManager.exportReportToPdfFile(printFileName, "E:/sample_report.pdf");

                JRXlsExporter exporter = new JRXlsExporter();
                exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, printFileName);
                exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "E:/sample_report.xls");

                exporter.exportReport();
                System.out.println("done!!!!!!!!!!!!!!!!");
            }
        }catch (JRException e) {
            e.printStackTrace();
        }
    }
}
0
votes

You asked for help to know how to design your XML dataset, I would rename the author tag to authorFirstName and authorLastName so that there is no confusion on Birt's end.