. Join Database with XML Datasource in BIRT
You have data from a standard database. But you need to join additional data from an XML source.
For example, cities
table is from a database:
CID NAME POPULATION STATEID
----- ----- ----- -----
1 New York 8084316.0 32
2 Los Angeles 3798981.0 5
3 Chicago 2886251.0 13
4 Houston 2009834.0 43
5 Philadelphia 1492231.0 38
6 Phoenix 1371960.0 3
state
table is from an xml file:
<?xml version="1.0" encoding="utf-8"?>
<data>
<state>
<STATEID>1</STATEID>
<NAME>"Alabama"</NAME>
<ABBR>"AL"</ABBR>
</state>
<state>
<STATEID>2</STATEID>
<NAME>"Alaska"</NAME>
<ABBR>"AK"</ABBR>
</state>
</data>
The output you want:
STATE POPULATION
----- -----
Alabama 431422.0
Alaska 278700.0
Solution:
1) You can use a Scripted Data Source and use java to parse the XML.
- Define an XML Datasource or a scripted Datasource if the XML file isn’t supported by original XML Datasource.
- Define XML dataset or scripted dataset of the previous Datasource.
- Define dataset from database Datasource.
- Define joint dataset with two datasets.
- create a crosstab from the joint dataset, with the new dataset columns as the data cube groups.
- Define the output column.
2) You can use esProc as Data Source and use SPL to join Database with XML Datasource.
Here is the SPL script.
A | |
1 | =demo.query("select * from cities where stateid=1 or stateid=2") |
2 | =xml(file("./states.xml").read(),"data/state") |
3 | =A2.new(int(STATEID):STATEID,NAME).keys(STATEID) |
4 | >A1.switch(STATEID,A3:STATEID) |
5 | =A1.groups(STATEID;sum(POPULATION):POPULATION,STATEID.NAME:STATE) |
6 | =A5.new(STATE,POPULATION) |
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.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL