Use XML as Datasource in BIRT Report


You have to use an XML as a data source in your report. The XML has multiple child tags with the same name(ex. author). Refer to the XML pasted below.


<title>Basic Mathematics</title>


1) Using XML Datasource

You add an XML data source and a dataset in your report. You make the following mappings in my XML dataset.

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

In the data set, you are getting three records, one for each of the tags. 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 recognized by the BIRT. You need to get both “Roy” & “Jon” from the second Book element. And, you need to get both “Harry” & “Potter” from the third Book element. You can’t get all the values from tags with the same name into the dataset. You would rename the author tag to authorFirstName and authorLastName so that there is no confusion on Birt’s end.

2) Using esProc Datasource

Here is the esProc SPL script:

1 =file("./BookStore.xml")
2 =xml(
3 =A2.BookStore.Book
4,   if(ifa(author),author.concat("&"),author):author,
      if(ifstring(copies),int(replace(copies,";","")),copies):copies,   price)



A4: Cleans up and unifies column data types and returns the final result.


The report can be designed in the same way as you would if you were retrieving the data from a database. For detail SPL integration with BIRT, see How to Call an SPL Script in BIRT.

For more examples, procedure XML files refer to the following XML data parsing and calculation.

If you have any questions or comments please leave them below.