Andreas Saremba
Andreas Saremba

Reputation: 93

BIRT: Specifying XML Datasource file as parameter does not work

Using BIRT designer 3.7.1, it's easy enough to define a report for an XML file data source; however, the input file name is written into the .rptdesign file as constant value, initially. Nice for the start, but useless in real life. What I want is start the BIRT ReportEngine via the genReport.bat script, specifying the name of the XML data source file as parameter. That should be trivial, but it is surprisingly difficult...

What I found out is this: Instead of defining the XML data source file as a constant in the report definition you can use params["datasource"].value, which will be replaced by the parameter value at runtime. Also, in BIRT Designer you can define the Report Parameter (datasource) and give it a default value, say "file://d:/sample.xml".

Yet, it doesn't work. This is the result of my Preview attempt in Designer:

Cannot open the connection for the driver: org.eclipse.datatools.enablement.oda.xml.
org.eclipse.datatools.connectivity.oda.OdaException: The xml source file cannot be found or the URL is malformed.

ReportEngine, started with 'genReport.bat -p "datasource=file://d:/sample.xml" xx.rptdesign' says nearly the same. Of course, I have made sure that the XML file exists, and tried different spellings of the file URL. So, what's wrong?

Upvotes: 4

Views: 5231

Answers (2)

Chopchop
Chopchop

Reputation: 2949

Since this is an old thread but still usefull, i ll add some info :

  • In the edit datasource, add some url to have sample data to create your dataset
  • Create your dataset
  • Then remove url as shown

enter image description here

add some script

enter image description here

Upvotes: 0

user359040
user359040

Reputation:

What I found out is this: Instead of defining the XML data source file as a constant in the report definition you can use params["datasource"].value, which will be replaced by the parameter value at runtime.

No, it won't - at least, if you specify the value of &XML Data Source File as params["datasource"].value (instead of a valid XML file path) at design time then you will get an error when attempting to run the report. This is because it is trying to use the literal string params["datasource"].value for the file path, rather than the value of params["datasource"].value.

Instead, you need to use an event handler script - specifically, a beforeOpen script.

To do this:

  • Left-click on your data source in the Data Explorer.
  • In the main Report Design pane, click on the Script tab (instead of the Layout tab). A blank beforeOpen script should be visible.
  • Copy and paste the following code into the script:

this.setExtensionProperty("FILELIST", params["datasource"].value);

If you now run the report, you should find that the value of the parameter datasource is used for the XML file location.

You can find out more about parameter-driven XML data sources on BIRT Exchange.

Upvotes: 8

Related Questions