[英]Use xml as data source in birt report programmatically
我是birt的新手,正在尝试使用xml作为数据源,但是我不明白它的作用。 我不知道是否有必要指定更多数据,但是我没有找到任何说明来指定将xml用作数据源所必需的内容。
我使用下一个代码:
/** Set data source */
void buildDataSource() throws SemanticException {
OdaDataSourceHandle dsHandle = this.efactory.newOdaDataSource("Data Source", "org.eclipse.datatools.enablement.oda.xml");
dsHandle.setProperty("FILELIST", "http://localhost:8080/BirtIntegrationImproved/ReportXmlDatasource/books.xml");
this.design.getDataSources().add(dsHandle);
}
/** Set data set */
void buildDataSet() throws SemanticException {
OdaDataSetHandle dsHandle = this.efactory.newOdaDataSet("ds","org.eclipse.datatools.enablement.oda.xml.dataSet");
dsHandle.setDataSource("Data Source");
this.design.getDataSets().add(dsHandle);
}
/** List of columns */
ArrayList<String> cols = new ArrayList<String>();
cols.add("id");
cols.add("author");
cols.add("title");
cols.add("genre");
cols.add("price");
buildDataSource();
buildDataSet();
TableHandle table = this.efactory.newTableItem("table", cols.size());
table.setWidth("100%");
table.setDataSet(this.design.findDataSet("ds"));
PropertyHandle computedSet = table.getColumnBindings();
ComputedColumn cs1 = null;
for( int i=0; i < cols.size(); i++) {
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols.get(i));
cs1.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]");
computedSet.addItem(cs1);
}
// table header
RowHandle tableheader = (RowHandle) table.getHeader().get(0);
for(int i=0; i < cols.size(); i++) {
LabelHandle label1 = this.efactory.newLabel((String)cols.get(i));
label1.setText((String)cols.get(i));
CellHandle cell = (CellHandle) tableheader.getCells().get(i);
cell.getContent().add(label1);
}
// table detail
RowHandle tabledetail = (RowHandle) table.getDetail().get(0);
for(int i=0; i < cols.size(); i++) {
CellHandle cell = (CellHandle) tabledetail.getCells().get(i);
DataItemHandle data = this.efactory.newDataItem("data_"+(String)cols.get(i));
data.setResultSetColumn((String)cols.get(i));
System.out.println("ResultSetColumn: " + data.getResultSetColumn());
cell.getContent( ).add(data);
}
有人知道怎么了吗?
谢谢!!
要从xml作为数据源获取数据,您需要执行以下步骤:
1.使用填充到系统上任何路径的数据保存xml。
2.将此路径映射到数据源。
3.映射要在数据集中的报表上查看的xml中的字段。
现在可以按照与从数据库检索数据时相同的方式来设计报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.