Home
Analytics
How Do I Iterate a Data Set With an XML Data Source In beforeFactory?
dbmathis
<p>Hi All,</p>
<p> </p>
<p>I am using BIRT 3.7.2.</p>
<p> </p>
<p>I have an XML data source and several data set from that XML source. I need to iterate through one of the data sets in the beforeFactory so that i can do some manipulation to the master page based on some data.</p>
<p> </p>
<p>I have seen the dev shares that show how to do this with a SQL data source, but nothing for XML.</p>
<p> </p>
<p>Can someone please provide me with an example of how this is done?</p>
<p> </p>
<p>Thanks.</p>
Find more posts tagged with
Comments
JFreeman
<p>You can use the DevShare example on using the <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/files/file/822-data-engine-api-to-check-data-set-values/'>Data
Engine API to check Data Set values</a> with some modifications to make it work with an XML data source instead of JDBC. The only changes required for XML are modifying the ExtensionID and properties for the odaDataSource/Set which can be obtained from the XML Source of the report design.</p>
<p> </p>
<p>After the modifications my code looked like this:</p>
<p style="margin-left:40px;"> </p>
<div style="margin-left:40px;">importPackage( Packages.org.eclipse.birt.report.model.api );</div>
<div style="margin-left:40px;">importPackage(Packages.java.lang);</div>
<div style="margin-left:40px;">importPackage(Packages.java.util);</div>
<div style="margin-left:40px;">importPackage(Packages.org.eclipse.birt.data.engine.api);</div>
<div style="margin-left:40px;">importPackage(Packages.org.eclipse.birt.report.model.api);</div>
<div style="margin-left:40px;">importPackage(Packages.org.eclipse.birt.data.engine.api.querydefn);</div>
<div style="margin-left:40px;">importPackage(Packages.org.eclipse.birt.data.engine.core);</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();</div>
<div style="margin-left:40px;">var de = DataEngine.newDataEngine( myconfig, null );</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">var dsrc = reportContext.getDesignHandle().findDataSource("Data Source");</div>
<div style="margin-left:40px;">var dset = reportContext.getDesignHandle().findDataSet("Data Set");</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">var odaDataSource = new OdaDataSourceDesign("Test Data Source");</div>
<div style="margin-left:40px;">odaDataSource.setExtensionID("org.eclipse.datatools.enablement.oda.xml");</div>
<div style="margin-left:40px;">odaDataSource.addPublicProperty("FILELIST", dsrc.getProperty("FILELIST").toString());</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">var odaDataSet = new OdaDataSetDesign("Test Data Set");</div>
<div style="margin-left:40px;">odaDataSet.setDataSource(odaDataSource.getName());</div>
<div style="margin-left:40px;">odaDataSet.setExtensionID("org.eclipse.datatools.enablement.oda.xml.dataSet");</div>
<div style="margin-left:40px;">odaDataSet.setQueryText(dset.getQueryText());</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">de.defineDataSource( odaDataSource );</div>
<div style="margin-left:40px;">de.defineDataSet( odaDataSet );</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">queryDefinition = new QueryDefinition( );</div>
<div style="margin-left:40px;">queryDefinition.setDataSetName( odaDataSet.getName() );</div>
<div style="margin-left:40px;">queryDefinition.setAutoBinding(true);</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">var pq = de.prepare( queryDefinition );</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">var qr = pq.execute( null );<span> </span></div>
<div style="margin-left:40px;">var ri = qr.getResultIterator( );<span> </span></div>
<div style="margin-left:40px;">while ( ri.next( ) )</div>
<div style="margin-left:40px;">{<span> </span></div>
<div style="margin-left:40px;">if(ri.getString(ri.getResultMetaData().getColumnName(1)) == "MO"){</div>
<div style="margin-left:80px;">//Master Page logic goes here.</div>
<div style="margin-left:40px;">}</div>
<div style="margin-left:40px;">}</div>
<div style="margin-left:40px;"> </div>
<div style="margin-left:40px;">ri.close( );</div>
<div style="margin-left:40px;">qr.close( );</div>
<div style="margin-left:40px;">de.shutdown( );</div>
dbmathis
Thank you! Worked perfectly.