Developing XML Publisher Reports using Data Template
Data template is one of the method of generating reports in XMLP. Reports in XMLP has two components:
- Data Definition
- Template
Data Definition
Data definition is a component which pulls out data from a data source and generates the data file in an XML format with a user defined structure.
Template
Template is a layout which can be designed using Word of Excel.
XML Publisher engine requires input data in an XML format, XML file is processed by XML Publisher engine and the same data displayed in the layout. We can generate XML file using any kind of program, usually we do using:
- Oracle Report Builder (RDF)
- PL/SQL Program
- Java Program
- Data Template
In this article, we will focus on how to generate data in XML file using Data Template.
Data Template
The data template is the method by which you communicate your request for data to the data engine. It is an XML document whose elements collectively define how the data engine will process the template to generate the XML.
Data Template Definition
The data template is an XML document that consists of 5 basic sections:
- Properties
- Parameters
- Triggers
- Data Query
- Data Structure
Below is the basic structure of Data Template:
Data Template Declaration
The element is the root element. It has a set of related attributes expressed within the tag.
Example:-
Below are the different possible attributes:
ATTRIBUTE NAME | DESCRIPTION |
---|---|
name | (Required) Enter the data template name |
description | (Optional) Enter a description of this data template |
version | (Required) Enter a version number for this data template |
defaultPackage | (Optional) This attribute is required if your data template contains lexical references or any other calls to PL/SQL |
dataSourceRef | (Optional) The default data source reference for the entire data template |
Properties Section
Use the section to set properties to affect the XML output and data engine execution.
Example:-
The following table shows the supported properties:
PROPERTY NAME | DESCRIPTION |
---|---|
include_parameters | Indicates whether to include parameters in the output. Valid values are:
|
include_null_Element | Indicates whether to remove or keep the null elements in the output. Valid values are:
|
xml_tag_case | Allows you to set the case for the output XML element names. Valid values are:
|
db_fetch_size | Sets the number of rows fetched at a time through the jdbc connection. The default value is 500. |
scalable_mode | Sets the data engine to execute in scalable mode. This is required when processing a large volume of data. Valid values:
|
include_rowsettag | Allows you to include or exclude the Rowset Tag from the output. Valid values:
|
debug_mode | Turns debug mode on or off. Valid values:
|
Parameters Section
A parameter is a variable whose value can be set at runtime, usually we get parameter value from the concurrent program parameters. Parameters defined in the data template must be in the same order of the parameters defined in the concurrent program. The Parameters section of the data template is optional.
The element is placed between the open and close tags. The element has a set of related attributes namely
ATTRIBUTE NAME | DESCRIPTION |
---|---|
name (required) | The parameter name that will be referenced in the template. |
dataType | Valid values are: “character”, “date”, “number” |
defaultValue | Value to use for the parameter if none supplied from the data |
include_in_output | Whether this parameter should appear in the XML output or not. The valid values are “true” and “false”. |
Parameters can be accessed in the data query part of data template using bind variables. Eg:- :p_deptno
Triggers Section
Triggers are optional elements of data template which are nothing but a PL/SQL Function or a Procedure which gets executed at specific times during the execution and generation of XML output. Triggers can be used to perform some pre and post execution activities like in financial reports where we update some table columns stating that a particular is row is printed.
Data triggers are optional, and you can have as many elements as necessary.
The element has a set of related attributes. These are expressed within the tag. For example, the name and source attributes are expressed as follows:
ATTRIBUTE NAME | DESCRIPTION |
---|---|
name | The event name to fire this trigger |
source | The PL/SQL < package name >.< function name > where the executable code resides. |
The location of the trigger indicate at what point the trigger fires:
- Place a beforeReport trigger anywhere in your data template before the < dataStructure > section.. A beforeRepot trigger fires before the dataQuery is executed.
- Place an afterReport trigger after the < dataStructure > section. An afterReport trigger fires after you exit and after XML output has been generated.
Data Query
Data Query is a mandatory element where we place the SQL statement which gets executed to fetch the information to be printed on the report output. We can have multiple SQL statements in DataQuery differentiated with a ‘name’ for the SQL Statement.
Example:
Example
Step 1 – Define Data Template
Create a data definition with below code:
Create a data definition with below code:
Step 2 – Define Package
Default Package used in data template
Default Package used in data template
Package Specification:
Package Body:
Note: In Data template when you define default Package, its mandatory to declare all the parameters of concurrent program as global variable in the default package.
Step 7 – Creating RTF Template
Run Concurrent program to generate XML data file which can be used to build XML template.
Run Concurrent program to generate XML data file which can be used to build XML template.
Create a blank rtf file with name ‘XX_EMP_DEPT.rtf’ and Load generated XML Data file to RTF
Click here to download RTF, Data template and package used in this article.
Thanks for sharing this Informative content. Well explained.
ReplyDeleteVisit us: Dot Net Online Training Hyderabad
Visit us: .net online training india