Blogs

Ted Ueda

Crystal Reports for Eclipse Version 2 - Programmatically Create Reports off of XML or Web Services Data Sources
Ted Ueda SAP Employee Active Contributor Silver: 500-1,499 points
Business Card
Company: SAP
Posted on Feb. 02, 2009 12:16 AM in Enterprise Data Warehousing/Business Warehouse, Business Intelligence (BusinessObjects), Java Programming, SAP Crystal Reports

Subscribe.Subscribe
Print. Print
Permalink Permalink
Share

I work for SAP Business Objects in Technical Customer Assurance.  My speciality is the Software Development Kits (SDKs) that we provide with our Business Intelligence products - BusinessObjects Enterprise, Web Intelligence, Desktop Intelligence, Crystal Reports and Crystal Xcelsius. 

In my blog, I discuss subjects that I personally find interesting - little known or not-well-documented corners of the SDK, new functionality or new SDKs, or interesting issues that I've come across in a SAP Incident or SAP Developer Network forums. 

You're more than welcome to suggest any topic (SAP Business Objects SDK related, of course...) that you'd like me to discuss - I have a dozen or so items on my blog to-do list, but I'm always on the hunt for anything interesting with our SDKs.   

The new Crystal Reports for Eclipse Version 2 brings a feature-rich report design tool to the Eclipse Platform.   To utilize the Platform enviroment, the report designer uses the Eclipse Database Explorer and SQL Views to represent database connections - you can drag-and-drop Tables and Stored Procedures that you define in the Database Explorer onto the Data View of the designer to insert it into a report.

Unfortunately, there's an impedance mismatch between the Web Services and XML data sources as presented by the Database Explorer and Crystal Reports rpt format.  You can't drag-and-drop these data sources into a report at this time.

Crystal Reports has its own representation of XML and Web Services connectivity, and it's something that can be used cross-platform: via the Crystal Reports Java (CRJ) SDK, the Crystal Reports .NET (CR.NET) SDK, the Report Application Server (RAS), and even Crystal Reports Server or BusinessObjects Enterprise - scalable from tens to thousands of users!

If you have a copy of Crystal Reports 2008, then you can fully design a report against XML or Web Services data sources and take advantages of the features available with the CR 2008 designer.

Coders without a copy of CR 2008 who require reporting off of XML or Web Services data sources, however, aren't left out in the cold.

You can use the new Crystal Reports Java report creation/modification API features to programmatically create reports off of these data sources!

In this blog entry, I'll present code snippets that show you how to create reports off of XML - either from HTTP or local files - and Web Services, including Query as a Web Service (QaaWS) and RSS 2.0.

Sample Codes

Here's a brief outline of the workflow:  (1) connect to the Crystal Reports Java report engine, (2) define XML or Web Services connection info, (3) define the data source as a Table or Procedure, (4) add to the report and save.

Once you programmatically create a report using CRJ, then you can open the report in the CR4E embedded designer, and use the table or procedure data fields in the report - you need not go through the Eclipse Database Explorer to access the connection.

Since the width restrictions current with SCN limits the column size and obscures the formating, I recommend copying the content of each sample to a text editor for ease-of-reading.

Crystal Reports off of local XML data file

First sample creates a report off of a XML file, where the schema is defined in a XSD file:

Create Crystal Report against customer.xml and customer.xsd

You can find the copy of the XML and XSD here: customer.xml customer.xsd.

Crystal Reports off of HTTP XML data URL

Instead of reporting off of a local XML file, let's report off of the HTTP URL where the XML and XSD are found:

Create Crystal Report  from HTTP XML data source

The code defines connections to customer.xml customer.xsd and orders.xml orders.xsd, specifies data sources as Procedure objects, then creates a TableJoin to link the two.

Crystal Reports off of local XML file with inline schema

The following code creates a report off of a local XML file, where the XML contains the schema definition in-line:

Create Crystal Report against XML file with inline schema

Here's the inline_schema.xml file that the above report utilizes:

XML with inline schema

Note: as per comments below, because of changes to the Open Source XML parsers used, if you want to consume the above inline schema in Crystal Reports 2008 Service Pack 2 Designer, you'll have to change <root xmlns:inl="http://inline"> to <root>, and all instances of <inl:Person> to <inl:Person xmlns:inl="http://inline">.

 

Crystal Reports off of RSS 2.0

Here's a sample for creating a Crystal Report against a RSS 2.0 feed - the feed is from the SCN Crystal Reports - Java Development Forum:

Create Crystal Reports against a RSS 2.0 feed

The above code uses the RSS 2.0 schema XSD as created by TheArchitect.co.uk.

Crystal Reports off of a Web Service

Query as a Web Service is a easy-to-use tool for exposing data from a Business Objects Enterprise Universe Semantica Layer as a Web Service XML Schema.  The following sample shows how to create a Crystal Report reporting off of a Web Service:

Create Crystal Reports against a Web Services - QaaWS

The QaaWS parametrizes Enterprise authentication credentials, and this is modeled within the connectivity as stored procedure parametrizations.

Crystal Reports off of a Web Services as a local WSDL File

You can specify Web Services connectivity to a local WSDL file, to allow for redirection to a different Web Services URL:

Create Crystal Reports against a local WSDL file

For reference, here's the WSDL as generated by the QaaWS:

Query as a Web Service generated WSDL

You can see how the service module names are mapped to the connection properties in the report.

All the above code samples will create a skeleton report with just the XML or Web Services connection and data source defined.   Just open the report in Crystal Reports for Eclipse embedded designer, to complete your report creation.

Summary

To have full design capability for XML or Web Services data sources, you would require the Crystal Reports 2008 Designer product.

However, even without CR 2008, you can still programmatically create Crystal Report reports off of XML or Web Services using the Crystal Reports Java SDK. 

It's something you couldn't do with previous versions of CR4E!

(Postscript: for more sample codes - Shawn's report creation/modification samples included - see my blog here: Crystal Reports for Eclipse 2.0 - Sample Codes Package)

 

Ted Ueda  Active Contributor Silver: 500-1,499 points is a Senior Support Engineer with SAP


Comment on this articleAny tips/tricks for Crystal Reports reporting off of XML or Web Services? Post here!
Comment on this weblog
Showing messages 1 through 16 of 16.

Titles Only Main Topics Oldest First

  • Error on crdb_xml
    2010-12-20 08:08:28 domnic savio Business Card [Reply]

    Hi Ted,
    I am trying to run the first example, I am getting an error at


    propertyBag.put("Database DLL", "crdb_xml.dll");


    The crdb_xml.dll is not loading as it is not found and looks like it is not recommended.


    neither are they found in any downloads from
    https://forums.sdn.sap.com/thread.jspa?threadID=1195618&tstart=0


    Is there any alternative driver to load for XML files in Eclipse..?
    thanks
    Domnic

  • losein the connection
    2009-12-30 02:56:24 Amanda Tahhan Business Card [Reply]

    Dear Red,
    I'm connectiong to database and passing selection formula to the report programmatically
    it works fine for the first time then I lose the connection and the parameters value one the user clicks on navagation toolbar or to export the report.
    what to do? I'v asked so many people and no one helped me
    my job is on the line here if I don't solve this issuu
    thank you
  • SP2 breaks these examples
    2009-10-26 20:50:42 Paul Joyce Business Card [Reply]

    Hi Ted,


    I have just installed Crystal Reports 2008 Service Pack 2 (file cr2008win_sp2.exe) and started having problems with XML data sources with inline schema. So I tried your examples. The sample works with CR 2008, SP0, SP1 but NOT with SP2. The following error is thrown when you try to connect to the data source (press Finish on the wizard)


    Logon failed.
    Details: Schema file is invalid
    error: src-resolve.a: Could not find element 'Person@http://www.w3.org/2000/xmlns/'. Do you mean to refer to the element named Person@http://inline?


    It looks like the rules for the inline schema have changed, but to what??


    Getting really sick of breaking changes being made to Crystal Reports on every version, service pack, etc. It is a nightmare trying to keep our product stable.

    • SP2 breaks these examples
      2009-10-26 22:21:38 Ted Ueda SAP Employee Business Card [Reply]

      Change


      <root xmlns:inl="http://inline">


      to


      <root>


      and change all instances of


      <inl:Person>


      to


      <inl:Person xmlns:inl="http://inline">


      Sincerely,


      Ted Ueda

    • SP2 breaks these examples
      2009-10-26 22:19:23 Ted Ueda SAP Employee Business Card [Reply]

      To be fair to the Crystal data driver guys, the XML driver uses Java and Axis2, which makes it bit of a moving target for schemas before the data even hits the Crystal side.


      The error message you see is straight from the open source XML parser.


      To have it work with XI 3.x SP2, you have to alter the root namespace tag header.


      Remove the attribute from root by changing:


      <root xmlns:inl="http://inline">


      to


      <root>


      and specify the tag header instead in the Person tags by modifying all instances of:


      <inl:Person>


      to


      <inl:Persion xmlns:inl="http://inline">


      Sincerely,


      Ted Ueda

    • SP2 breaks these examples
      2009-10-26 22:14:51 Ted Ueda SAP Employee Business Card [Reply]

      To be fair to the Crystal data driver guys, the XML driver uses Java and Axis2 for the XML parser, and it's always a bit of a moving target before it even reaches the Crystal side.


      In the example above, you have to remove the root attribute, by changing:


      <root xmlns:inl="http://inline">


      to


      <root>


      and specify the tag header in each Person tag by changing all instances of:


      <inl:Person>


      to


      <inl:Person xmlns:inl="http://inline">


      Sincerely,


      Ted Ueda

  • Data is not correct with Crystal Report 2008 and CRJ SDK 12 run time.
    2009-02-13 00:36:53 nha nguyen Business Card [Reply]

    Dear Ted,


    I have a problem below:


    when i create the crystal report 2008 with xml schema and xml data below, i must get 6 records on the report, but it just show 4 records.


    I also encountered this error with CRJ SDK 12 run time.


    Please help me to explain and fix this error.


    xml schema:


    <?xml version="1.0" encoding="ISO-8859-1"?>
    <Document_Policy>
    <PrimaryKey>000</PrimaryKey>
    <Policy_AllCoverages>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>111</PrimaryKey>
    <CVG_NUM>A</CVG_NUM>
    </Policy_AllCoverages>
    <Policy_AllCoverages>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>222</PrimaryKey>
    <CVG_NUM>B</CVG_NUM>
    </Policy_AllCoverages>
    <Policy_AllCoverages>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>333</PrimaryKey>
    <CVG_NUM>C</CVG_NUM>
    </Policy_AllCoverages>
    <Policy_Beneficiary>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>ID1</PrimaryKey>
    <BNFY_NM>Bill Gate</BNFY_NM>
    </Policy_Beneficiary>
    <Policy_Beneficiary>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>ID2</PrimaryKey>
    <BNFY_NM>Michael Dell</BNFY_NM>
    </Policy_Beneficiary>
    </Document_Policy>


    xml data:



    <?xml version="1.0" encoding="ISO-8859-1"?>
    <Document_Policy>
    <PrimaryKey>000</PrimaryKey>
    <Policy_AllCoverages>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>111</PrimaryKey>
    <CVG_NUM>A</CVG_NUM>
    </Policy_AllCoverages>
    <Policy_AllCoverages>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>222</PrimaryKey>
    <CVG_NUM>B</CVG_NUM>
    </Policy_AllCoverages>
    <Policy_AllCoverages>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>333</PrimaryKey>
    <CVG_NUM>C</CVG_NUM>
    </Policy_AllCoverages>
    <Policy_Beneficiary>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>ID1</PrimaryKey>
    <BNFY_NM>Bill Gate</BNFY_NM>
    </Policy_Beneficiary>
    <Policy_Beneficiary>
    <ForeignKey>000</ForeignKey>
    <PrimaryKey>ID2</PrimaryKey>
    <BNFY_NM>Michael Dell</BNFY_NM>
    </Policy_Beneficiary>
    </Document_Policy>





Showing messages 1 through 16 of 16.