Professional Documents
Culture Documents
Nature of Document: Tip or Technique Product(s): IBM Cognos 8 BI Area of Interest: Infrastructure, Modeling
Business Analytics
IBM Cognos 8 BI XML as a Data Source Copyright and Trademarks Licensed Materials - Property of IBM. Copyright IBM Corp. 2010
IBM, the IBM logo, and Cognos are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at http://www.ibm.com/legal/copytrade.shtml While every attempt has been made to ensure that the information in this document is accurate and complete, some typographical errors or technical inaccuracies may exist. IBM does not accept responsibility for any kind of loss resulting from the use of information contained in this document. The information contained in this document is subject to change without notice. This document is maintained by the Best Practices, Product and Technology team. You can send comments, suggestions, and additions to cscogpp@ca.ibm.com.
Business Analytics
Table of Contents
1 Introduction..................................................................................................................4
1.1 1.2 1.3 1.4 Purpose........................................................................................................................ 4 Applicability.................................................................................................................. 4 Assumptions................................................................................................................. 4 Exceptions.................................................................................................................... 4
2 Overview...................................................................................................................... 4 3 Valid XML for IBM Cognos 8........................................................................................... 4 4 Connect to an XML File on the File System...................................................................... 6 5 Connect to an XML File over HTTP..................................................................................9 6 Transform XML for Use in IBM Cognos 8....................................................................... 11 7 Setting up the Provided Sample....................................................................................13
7.1 7.2 7.3 7.4 8.1 8.2 Unpack the Installation................................................................................................ 13 Configure the Installation............................................................................................. 13 Build the WAR file........................................................................................................ 14 Deploy the WAR file..................................................................................................... 14 Run a Script to Generate an XML File............................................................................ 15 Call a JSP to Stream XML Data Over HTTP..................................................................... 17
9 Conclusion...................................................................................................................19
Business Analytics
1 Introduction
1.1 Purpose
This document will illustrate techniques for connecting to XML data sources with IBM Cognos 8.
1.2 Applicability
The techniques in this document were tested with IBM Cognos 8 BI version 8.4.
1.3 Assumptions
This document assumes familiarity with Framework Manager, XML, JSP code, shell scripts, and deploying an application to an application server or servlet/JSP container. Administrator privileges will be required to create data sources in IBM Cognos 8.
1.4 Exceptions
The techniques in this document are intended for smaller XML data sets. Testing is required to ensure acceptable performance in the environment these techniques are used. For larger data sets or more flexible XML implementations consider using IBM Cognos Virtual View Manager.
2 Overview
IBM Cognos provides many types of data sources to connect to for reporting. XML is one of them and is done without any extra infrastructure requirements such as middleware. Administrators can connect directly to an XML file, or access XML via a URL. For the latter, the XML source can be an XML file residing in a Web server directory, or can be XML that is streamed programmatically, such as with a JavaServer Page (JSP). This document will provide examples of how to implement these methods.
Business Analytics
Please refer to the xmldata.xsd schema file and the documentation for more information and a full listing of the supported data types. Below is a small example of what a valid IBM Cognos 8 XML data source looks like.
<?xml version="1.0" encoding="UTF-8"?> <dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http:// www.w3.org/2001/XMLSchema-instance"> <metadata> <item name="AsOfDate" type="xs:string" length="12"/> <item name="RateOfReturn" type="xs:double"/> <item name="FamAcctIndex" type="xs:string" length="3"/> <item name="RowID" type="xs:string" length="1"/> <item name="BrM" type="xs:string" length="1"/> <item name="ProductLineCode" type="xs:int"/> </metadata> <data> <row> <value>Apr 26, 2002</value> <value>0.210066429</value> <value>JA1</value> <value>F</value> <value>B</value> <value>1</value> </row> <row> <value>Apr 27, 2002</value> <value>0.1111111</value> <value>BBB</value> <value>G</value> <value>B</value> <value>2</value> </row> </data> </dataset>
Business Analytics
It is important to note that the length attribute affects the efficiency of processing the XML data by IBM Cognos 8. Memory is allocated to the number specified in the length attribute regardless of the actual size of the data. For example, if the largest piece of data for an element is 50 characters, but a higher value is chosen for the length attribute, such as 255, memory will be allocated for the full 255. It is recommended to specify a length as close as possible to the largest estimated piece of data. Again, for more flexible implementations of XML as a data source, consider using IBM Cognos Virtual View Manager.
Business Analytics
8. Click Next, and then in the Connection string box, enter the full or UNC path to the Test.xml file.
A UNC path is recommended when the XML file is on a share and needs to be accessed by
Business Analytics
multiple IBM Cognos 8 servers. If a local path is used, a copy of the XML file will need to be placed in that location on each IBM Cognos 8 server, whic requires more maintenance. 9. Click Finish, and then click Close. 10. Select xmlFileTest as a data source, and then click Next. 11. Select Tables. (In this portion of the UI, the tree can be expanded to see the items being imported as seen below.)
12. Click Next, click Import, and then click Finish. 13. In the Project Viewer pane, expand the xmlFileTest namespace. 14. Right-click the xmlFileTest query subject, click Test and then click Test Sample.
Business Analytics
The item names found in the XML document are represented by query items. At this point a package can be created and published to be used as a reporting source in IBM Cognos 8.
Business Analytics
10
8. Click Next, and then in the Connection string box, enter the full URL to the Test.xml file, in this case http://localhost/cognos8/Test.xml. It is recommended that localhost be replaced with the actual server name or IP address.
Business Analytics
11
13. Right-click the xmlOverHTTPTest query subject, click Test and then click Test Sample.
Again, the data in the XML file is retrieved, but this time over HTTP. 14. Click Close. At this point a package can be created and published to be used as a reporting source in IBM Cognos 8.
Business Analytics
12
In the diagram below, a calling application, which can be any one of a number of programming languages or shell scripts, retrieves the XML from the source location. For example, the application may pull an RSS feed from a web site. The calling application then references an XSLT file that is used to transform the source XML into a different XML document, in this case, one that is appropriate for IBM Cognos 8.
Calling Application
(Shell Script, JSP, etc.)
IBM Cognos 8
Referenced XSLT
The calling application can write the XML to a file which IBM Cognos 8 can connect to on the file system or over HTTP through a virtual directory. This is a good choice if the resulting XML document is larger in size and has relatively static data. If the calling application is Web-based, such as a JSP, it can directly stream the XML to IBM Cognos 8. This is more suitable when there is a requirement for real time data where the XML source is smaller in size (the transformation of the source XML will occur each time the JSP is called). Both cases will be demonstrated in subsequent sections. However, before testing each scenario, the application called devWorksXMLDS, which is provided with this document, will be deployed using the Tomcat servlet/JSP container which ships with IBM Cognos 8. If deploying to another application server such as IBM WebSphere, consult the documentation for deployment instructions.
Business Analytics
13
Unpack the installation to an IBM Cognos 8 server Edit files that may require modification Build a WAR file Deploy the WAR file to an application server or servlet container
If editing the devWorksXMLDS.sh file, the following lines may need to be updated to point to the JRE or JDK in that environment.
if [ "$JAVA_HOME" = "" ]; then JAVA_HOME=/usr/bin fi JAVA="$JAVA_HOME/java"
Business Analytics
IBM Cognos 8 BI XML as a Data Source 7.3 Build the WAR file
Build the WAR file by running the appropriate build script for the environment. For Windows, run <IBM Cognos 8 install location>/war/devWorksXMLDS/build.bat. For UNIX or Linux, run <IBM Cognos 8 install location>/war/devWorksXMLDS /build.sh.
14
The build scripts will create the <IBM Cognos 8 install location>/war/devWorksXMLDS/ devWorksXMLDS.war file. 7.4 Deploy the WAR file
In this example, the WAR file will be deployed to the IBM Cognos 8 Tomcat server. Ensure that IBM Cognos 8 is running. Copy the <IBM Cognos 8 install location>/war/devWorksXMLDS/devWorksXMLDS.war file to the <IBM Cognos 8 install location>/webapps directory. After a short time, the IBM Cognos 8 Tomcat server will automatically unpack the WAR file. The WAR file can subsequently be deleted once released by Tomcat. The deployed application contains required JAR files which are used by the application's shell scripts and JSP.
These jar files are required for the XML implementation and transformation. The XSLT processor used by this application is Xalan-J. Detailed information about Xalan-J can be found at http:// xml.apache.org/xalan-j. The devWorksXMLDS installation is now ready for use.
Business Analytics
15
IBM Cognos 8
Referenced XSLT
Again, this method is best suited for larger data sets and where the underlying data is relatively static. The data is refreshed by running the script on a pre-determined schedule. The syntax for running the script with parameters is: Windows
devWorksXMLDS <sourceXML> <xsltFile> <outputXML>
Unix or Linux
./devWorksXMLDS.sh <sourceXML> <xsltFile> <outputXML>
The sample scripts provide default values for the parameters, but if any parameter requires a different value than the default, all parameters must be specified.
Business Analytics
16
Once the script is run, an XML file appears in the specified output location which can be used as a data source for IBM Cognos 8. By default, the output location is the same location as the shell script.
This file can now be connected to in an IBM Cognos 8 data source connection through the file system as shown below:
The full connection string reads: C:\Program Files\cognos\c8\webapps\devWorksXMLDS\devWorksXMLDS.xml Again a UNC path is recommended so that the file may be accessed by multiple IBM Cognos 8 servers.
Business Analytics
17
If the XML file is in a virtual directory (as is the case with this example), the connection string would be as shown below:
The full connection string reads: http://localhost:9300/devWorksXMLDS/devWorksXMLDS.xml Localhost should be replaced by the server name or IP address.
IBM Cognos 8
Referenced XSLT
Business Analytics
18
The URL to call the JSP is http://<server>:<port>/devWorksXMLDS/devWorksXMLDS.jsp, where <server>:<port> is the the application server that the devWorksXMLDS web application was deployed to. This is the same URL to be specified when configuring the Connection String property for the IBM Cognos 8 data source. In this example, the URL to the JSP deployed to Tomcat is http://localhost:9300/ devWorksXMLDS/devWorksXMLDS.jsp where localhost is replaced by the actual server name or IP address. To test the application, enter the URL in a Web browser. The results should appear similar to the screen capture below.
The location of the source data and the XSLT file is specified within the JSP. The variable sXMLSrc specifies the location of the source XML data and the variable sXSLTFile specifies the location of the XSLT file.
Business Analytics
19
9 Conclusion
Using the steps and sample code provided with this document can help to quickly implement XML as a data source in an IBM Cognos 8 environment.
Business Analytics