Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
alternatives to using XML datasource
tapani108
Hello,<br />
<br />
I am interested in both best-practices and perhaps alternatives to using XML from a URL as a datasource.<br />
<br />
I have managed to create a report design, with an XML file as the data source. I created a table from that XML, which turned out nicely. I was able to run the report as well. <br />
<br />
Now, the XML source is generated by a jsp. This jsp is using classes that have collected data and made the necessary calculations before the data reaches the jsp. The jsp is calling generateXML() function in a variation of org.jdom.output.XMLOutputter. Using JDOM, the XML elements are generated and then sent back to the jsp which then outputs it. Simple, one would imagine.<br />
<br />
The problem is, the jsp is bound to a session which requires authentication. I have seen a few other posts in this forum where users have experienced problems with using an XML datasource from a URL. That problem was in my case solved by removing the session check altogether, and also using JDOM directly in the jsp to generate XML. Doing that enables the use of a URL which has an XML-generating jsp when creating Data Sets in Report Designer.<br />
<br />
Obviously, using a jsp without authentication will get me <em class='bbc'>absolutely nowhere. </em><br />
<br />
Now to my actual question:<br />
<br />
<strong class='bbc'>Are there alternatives to making this XML generation/parsing detour?</strong><br />
<br />
I can not get the data directly from the db since there is a bunch of logic to put it together from a bunch of tables before it makes sense. <br />
<br />
The data is available, readily calculated, within the classes and there could/should be a way to access that data without having to make and parse the XML. <br />
<br />
Can the Data Sets be built on the fly, for example? Somebody help me out with this, plz. I hope I have managed to formulate my question properly.<br />
<br />
Thanks in advance!
Find more posts tagged with
Comments
Virgil Dodson
Hi tapani108,<br />
<br />
I had a similar issue recently where I needed to access CSV data at a URL. I chose to use a Scripted Data Source and then write a small Java class that went after the data and parsed it myself... My code is below that you can use as a starting point to parse your XML if desired.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;
import java.util.Vector;
import au.com.bytecode.opencsv.CSVReader;
public class EclipseConData
{
public Vector readData(){
Vector rtnV = new Vector();
try {
URL url = new URL("http://testservername/2009/birtreport&nodoctype");
URLConnection urlC = url.openConnection();
CSVReader reader = new CSVReader(new InputStreamReader(url.openStream()),',', '"', 1);
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
rtnV.add(new String[]{nextLine[0],nextLine[1],nextLine[2],nextLine[3],nextLine[4],nextLine[5],nextLine[6],nextLine[7],nextLine[8],nextLine[9],nextLine[10],nextLine[11],nextLine[12],nextLine[13]});
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return (rtnV);
}
}
</pre>