Over a million developers have joined DZone.

Connecting to an XML datasource

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

XML is a popular data source used in many applications. JasperReports allows you to generate reports directly from XML data.

This article by Bilal Siddiqui, author of JasperReports 3.6 Development Cookbook, teaches you how to connect iReport to an XML file stored on your PC.

Getting ready

You need an XML file that contains report data. The EventsData.xml file is contained in the source code download of JasperReports 3.6 Development Cookbook (chap:4). Unzip the source code file for this article (chap:4) and copy the Task2 folder from the unzipped source code to a location of your choice.

How to do it...

  1. Run iReport; it will open showing a Welcome Window, as shown in the following screenshot:
  2. If you have not made any database connection so far in your iReport installation, you will see an Empty datasource shown selected in a drop-down list just below the main menu. Click on the Report Datasources icon shown encircled to the right of the drop-down list in the screen-shot shown below:
  3. A new window named Connections / Datasources will open, as shown below. This window lists an Empty datasource as well as the data sources you have made so far.
  4. Click the New button at the top-right of the Connections / Datasources window. This will open a new Datasource selection window, as shown in the following screenshot:
  5. Select XML file datasource from the datasources type list. Click Next.
  6. A new window named XML file datasource will open, as in the following screenshot:
  7. Enter XMLDatasource as the name for your new connection for the XML datasource in the text box beside the Name text field, as shown in the following screenshot:
  8. Click the Browse button beside the XML file text box to browse to the EventsData.xml file located in the Task2 folder that you copied in the Getting ready section. Click the Open button, as shown in the following screenshot:
  9. Select the Use the report XPath expression when filling the report option in the XML file datasource window, as shown in the following screenshot:
  10. Leave the other fields at their default values. Click the Test button to test the new XML datasource connection. You will see a Connection test successful message dialog.
  11. Click the Save button to save the newly created connection. A Connections / Datasources window will open showing your new XML datasource connection set as the default connection in the connections list, as shown highlighted in the following screenshot:

JasperReports 3.6 Development Cookbook

Over 50 recipes to create next-generation reports using JasperReports
  • Create, size, and position the titles, headers, footers, and body of your report using JasperReports and iReport
  • Enhance the look and feel of your report using background images, watermarks, and other such features
  • Create multi-page and multi-column reports using multiple types of data in the same report
  • Generate reports from Java Swing applications or from your web application
  • Part of Packt's Cookbook series: Each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}