Jump to content
We've recently updated our Privacy Statement, available here ×

Deploying XML Datasource Report


neilelliott

Recommended Posts

I've created a report which uses an XML Datasource and I want to deploy this to JasperServer so that people can run and view it.

I cannot see how to do this as at the moment it looks like you can only deploy a report against a DB Datasource (JDBC or JNDI) or a Bean datasource. Can it be done and if so how ?

Currently using JasperServer 3.7.1 and iReport 3.7.1.1

Thanks

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

That's interesting, I've been just looking into the same issue...

I researched the existing XML datasources and query executers. Here's a good description of how to use them.

It seems like there are two ways to get an XML datasource from a URL using JR standalone (without JR Server):

1. create datasource directly

- create a JRXmlDataSource by passing the URL to the constructor

- pass the datasource in the "REPORT_DATA_SOURCE" parameter

2. use one of the query executers

- fetch the contents of the URL and parse it into an org.w3c.xml.Document

- create a query in your JRXML with language set to "xPath" and a queryString containing the XPath of the elements you want to iterate over

- pass the document object in the "XML_DATA_DOCUMENT" parameter

 

In either of these cases, you need to have some Java code for setup--either building the JRXmlDatasource or parsing the XML. In JRServer, you would have to do this with a custom data source.

One of the sample custom data sources (under samples/customDataSource in the JRServer install directory) is the so-called "webscraper" datasource. It's very similar to the XML query executer and data source. It can take the URL of an HTML page, fetch it, turn it into XML, and use an XPath to get a list of elements. I haven't tried it on an XML, but it might just work.

The good thing about this implementation is that you can use it in JR Server either with or without a custom data source instance, because it can get the URL and XPath right from the queryString.

If you want to check this out, you can get info about custom data sources (including the samples) in the JR Server doc, and there is also a readme.txt under samples/customDataSource. Here is the info from that file describing the Webscraper sample:


Webscraper Custom Data Source
The webscraper custom data source implementation can fetch a web page, decode the HTML, and extract selected data which is turned into field values in the data source. Its Spring bean definition file is located in <js-install>/samples/customDataSource/webapp/WEB-INF/applicationContext-webscraperDS.xml.

These are the configuration items for the datasource:

  • URL: An HTTP URL which refers to the HTML page containing the desired content
  • DOM path: An XPath expression which locates HTML elements to be turned into rows in the data source
  • Field paths: XPath expressions for each field defined in the JRXML which are used to locate the field value within each row selected by the DOM path


The implementation creates a data source by taking the following steps:

  • Uses the URL to issue a GET request for an HTML page.
  • Converts the HTML response into XML using JTidy (http://jtidy.sourceforge.net).
  • Uses the DOM path to select XML elements from the converted response.
  • Create a new data source row for each selected element
  • For each field, use the field path to determine the content for each field
  • The data source has two parameters: the URL of the web page, and the XPath that selects the elements in the HTML page which will become rows in the data source. The parameters can be specified either by a data source definition in the repository or by a query string in the JRXML.

The example reports for this data source read a web page from http://www.craigslist.org and extract a list of items for sale.

The file reports/webscrapertest.jrxml has no query defined. Instead, it relies on an instance of the custom data source
that has been created in the repository. Typical parameters to use with this data source are:

The file reports/webscraperQEtest.jrxml contains a queryString element which specifies the URL and the DOM path. It should be used without defining a data source instance, because JasperServer will not run the query executer for this particular implementation if a data source is defined for the report unit.

I hope this is useful for you! Let me know if you have any questions.



Post Edited by bobtins at 07/18/2011 20:13



Post Edited by bobtins at 07/18/2011 20:15
Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the reply. Been on a long vacation so not been able to respond until now..

This is exactly the route I've taken and have created my own datasource following the examples given (just hadn't got around to updating this forum).

fyi the XML document I wanted to point at was actually a Jasper Domain file. This can be accessed using the repository service. From all of this I've created a Domain report, describing the Jasper domain strucuture, mappings, descriptions and so on - turns out to be very useful for cataloging the domain.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...