Creating Jasper Reports In (iReport) Using XML As Data Source & Publishing It to Jasper Server

This blog will teach how to create Jasper Reports using iReport, the data source to be used is XML and then publish it on Jasper servcer

  1. Run iReport; it will open showing a Welcome Window, as shown in the following screenshot:

Jasperreport XML data source

2.  DataBase (DataSource ) Connection :

a.)  Click On Datasource button

Jasperreport XML data source 2

b) Click On new button

Jasperreport XML data source 3

C) Select XML datasource

Jasperreport XML data source 4

d) A new window named XML file datasource will open, as in the following

Jasperreport XML data source 5

e) Enter AddressBook (you can give the name of your choice also) as the name for your new connection for the XML datasource in the text box beside the Name text field  & Click the Browse button to browse to the addressbook.xml file located in the E:/ in my system. Select the Use the report XPath expression when filling the report option in the XML file datasource window,

Jasperreport XML data source 5

f) Now click on “TEST” for testing the connection

3. Creating The Report  :  Open a new report and then go to “query browser”,choose the query language from drop down list as “xpath.” The text area below the Query language drop-down list will split into two parts. The left part  shows the actual XPath expression, whereas the   right part shows XML nodes

Jasperreport XML data source 7

4. In the XML nodes right click on the name child of the person node,select “add node as field”,similarly for phone child of person node also.

Jasperreport XML data source 8

5. Double-click on the Fields node in the Report Inspector window on the left of your report. The Fields node will expand to show the fields name, phone.

Jasperreport XML data source Query

Drag-and-drop the name and phone field from the Fields node into the Detail section of your report.

6. Switch to the Preview tab and you will see your report The result should be similar to the below

Jasperreport XML data source 10

7. Publishing the report to the jasper server

a) Creating data adapter :

a.)    Creating Data Adapter :  To use flat files as a datasource (like  XML  files) you need to use DataAdapters in Jasperserver instead of regular datasources. We can create them manually in the server (it’s just an XML file). Data Adapter is a way to define a source for Jasper Reports using a   configuration file,(act as the bridge between data source and jasper reports while publishing the jasper report on Jasper Server).

xmlAdapter.xml

Jasperreport XML data source 11

<filename>repo:/reports/interactive/xmlData</filename>  – > here xmlData is the name of the xml    file(addressbook.xml) which we have to add again to the Jasper Server.(I have added this file in this location “repo:/reports/interactive/”.

b) We need to add XML datasource to server also

c) Adding xmlAdapter To The Properties attribute of Report.

Property Name : net.sf.jasperreports.data.adapter

Property Value : repo:/reports/interactive/xmlAdapter

 

Note: By default xpath or xpath2 language will not come in jasper server,for this you need to do three things…

  1. Copy jasperreports-extensions-3.5.3.jar from /ireport/modules/ext to JasperReports Server/jasperserver-pro/WEB-INF/lib/jasperreports-extensions-3.5.3.jar
  2. Add the following line to /jasperserver-pro/WEB-INF/classes/jasperreports.properties

net.sf.jasperreports.query.executer.factory.xpath2=com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory

  1. Restart Tomcat