# XML - Managing Data Exchange/Business Intelligence and XML

## Learning objectives

Upon completion of this chapter, for a single entity you will be able to

-   create a report specification entirely in XML for Cognos ReportNet
-   update a report specification in XML format.
-   identify four main sections in a report specification

## Introduction

Every report created in Cognos ReportNet has a specification that is
written in XML, so you can customize it using XML editor or create a
report specification entirely in XML.

## Report Specification Flow

After you save a report and open it again, the report specification is
pulled from the content store as you can see in Figure 28.1. When you
edit it, the changes remain local on the client machine until you save
it. When you save the report, the content store is updated.

Figure 28.1 Report Specification Flow

You can see a sample of web report in figure 28.2 and this report can be
generated from XML file;

Figure 28.2 Sample of a report

## XML in Report Specification Structure

A report specification consists of four main sections.

-   Report Section
    -   XML Tag:
        -   `<report>`{=html}
        -   `<modelConnection>`{=html}
-   Query Section
    -   XML Tag:
        -   `<querySet>`{=html}
-   Layout Section
    -   XML Tag:
        -   `<layoutList>`{=html}
-   Variable Section
    -   XML Tag:
        -   ```{=html}
            <variableList>
            ```

At minimum, a report specification must include the
`<report>`{=html}`</report>`{=html} tags, as well as authoring language
and schema information.

The specification header in Report Section includes information about:

-   authoring language, "en-us" indicates American English. You can use
    other language than English for the report
-   namespace : <http://developer.sample.com/schemas/report/1>
-   package name: GSR
-   model version : \@name=\'model\'

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<TR>
```
```{=html}
<TD bgcolor="lightyellow">
```
`<report xml:lang="en-us" xmlns="http://developer.sample.com/schemas/report/1/">`{=html}

`   ``<modelConnection name="/content/package[@name='GSR']/model[@name='model']"/>`{=html}

```{=html}
</pre>
```
```{=html}
</TD>
```
```{=html}
</TR>
```
```{=html}
</table>
```
The query section includes information about:

-   Cube elements are indicated by the `<cube>`{=html}`</cube>`{=html}
    tags which can contain:
    -   facts (`<factList>`{=html}`</factList>`{=html}. Country, First
        Name and Last Name are the facts.
    -   dimensions (`<dimension>`{=html}`</dimension>`{=html})
        consisting of levels(`<level>`{=html}`</level>`{=html})
    -   filters (`<filter>`{=html}`</filters>`{=html} consiting of
        conditions(`<condition>`{=html}`</conditions>`{=html}). Country
        is the filter for this report, which is equal to Germany.
-   Tabular model is contained in the
    `<tabularModel>`{=html}`</tabularModel>`{=html} tags.
    -   Each tabular model contains data items
        (`<dataItem>`{=html}`</dataItem>`{=html}) consisting of fully
        qualified expressions
        (`<expression>`{=html}`</expression>`{=html})
-   The query section of a report is contained in the
    `<querySet>`{=html}`</querySet>`{=html}tags.
-   The query section can include multiple queries, each of which is
    contained in the `<BIQuery>`{=html}`</BIQuery>`{=html}tags.

Add pages to a report specification:

-   You can add many pages to a report. Each page is outlined between
    the `<pageSet>`{=html} `</pageSet>`{=html}tags.
    -   Each page can consist of :
        -   a body ( mandatory)
        -   a header
        -   a footer

Add layout objects to a report:

-   Once you have added one or more pages to the report layout, you can
    add a variety of layout objects, such as :
    -   Text items
    -   Blocks
    -   Lists
    -   Charts
    -   Crosstabs
    -   Tables

Specify styles for layout objects:

-   You can use Cascading Style Sheets (CSS) attributes to determine the
    look and feel of objects in the layout.
-   CSS values are specified between the
    ```{=html}
    <style>
    ```
    ```{=html}
    </style>
    ```
    tags.
-   CSS values can apply to things like font sizes, background colors,
    and so forth.

Add Variables to a Report:

-   You can specify variables between the
    ```{=html}
    <variableList>
    ```
    ```{=html}
    </variableList>
    ```
    tags of the report specification., and each of variable includes an
    expression between the `<expression>`{=html}`</expression>`{=html}
    tags.
-   We can use Variable 1 that contains a list of possible values,
    example value: fr for using French language;

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<TR>
```
```{=html}
<TD bgcolor="lightyellow">
```
```{=html}
<variableList>
```
`        ``<variable name=”Variable1” type=”locale”>`{=html}\
`         ``<expression>`{=html}`ReportLocale()``</expression>`{=html}\
`          ``<variableValueList>`{=html}\
`           ``<variableValue value=”fr”/>`{=html}\
`          ``</varialeValueList>`{=html}\
`         ``</variable>`{=html}\
`        `

```{=html}
</variableList>
```
```{=html}
</pre>
```
```{=html}
</TD>
```
```{=html}
</TR>
```
```{=html}
</TABLE>
```
Below is the complete XML file for the report in Figure 28.3

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<TR>
```
```{=html}
<TD bgcolor="lightyellow">
```
    <report xml:lang="en-us" xmlns="http://developer.sample.com/schemas/report/1/">
        <!--RS:1.1-->
        <modelConnection name="/content/package[@name='GSR']/model[@name='model']"/>
        <querySet xml:lang="en-us">
            <BIQuery name="Query1">
                <cube>
                    <factList>
                        <item refItem="Country" aggregate="none"/>
                        <item refItem="First name" aggregate="none"/>
                        <item refItem="Last name" aggregate="none"/>
                    </factList>
                </cube>
                <tabularModel>
                    <dataItem name="Country" aggregate="none">
                        <expression>[gsrs].[addr].[Country]</expression>
                    </dataItem>
                    <dataItem name="First name" aggregate="none">
                        <expression>[gsrs].[Person].[First name]</expression>
                    </dataItem>
                    <dataItem name="Last name" aggregate="none">
                        <expression>[gsrs].[Person].[Last name]</expression>
                    </dataItem>
                    <filter>
                        <condition>[gsrs].[addr].[Country]='Germany'</condition>
                    </filter>
                </tabularModel>
            </BIQuery>
        </querySet>
        <layoutList>
            <layout>
                <pageSet>
                    <page name="Page1">
                        <pageBody>
                            <list refQuery="Query1">
                                <listColumnTitles>
                                    <listColumnTitle>
                                        <textItem>
                                            <queryItemRef refItem="Country" content="label"/>
                                        </textItem>
                                    </listColumnTitle>
                                    <listColumnTitle>
                                        <textItem>
                                            <queryItemRef refItem="First name" content="label"/>
                                        </textItem>
                                    </listColumnTitle>
                                    <listColumnTitle>
                                        <textItem>
                                            <queryItemRef refItem="Last name" content="label"/>
                                        </textItem>
                                    </listColumnTitle>
                                </listColumnTitles>
                                <listColumns>
                                    <listColumn>
                                        <textItem>
                                            <queryItemRef refItem="Country"/>
                                        </textItem>
                                    </listColumn>
                                    <listColumn>
                                        <textItem>
                                            <queryItemRef refItem="First name"/>
                                        </textItem>
                                    </listColumn>
                                    <listColumn>
                                        <textItem>
                                            <queryItemRef refItem="Last name"/>
                                        </textItem>
                                    </listColumn>
                                </listColumns>
                                <style>
                                    <CSS value="border-collapse:collapse"/>
                                </style>
                                <XMLAttribute name="RS_ListGroupInfo" value=""/>
                            </list>
                        </pageBody>
                        <pageHeader>
                            <block class="reportTitle">
                                <textItem class="reportTitleText">
                                    <text/>
                                </textItem>
                            </block>
                            <style>
                                <CSS value="padding-bottom:10px"/>
                            </style>
                        </pageHeader>
                        <pageFooter>
                            <table>
                                <tableRow>
                                    <tableCell>
                                        <textItem>
                                            <expression>AsOfDate()</expression>
                                        </textItem>
                                        <style>
                                            <CSS value="vertical-align:top;text-align:left;width:25%"/>
                                        </style>
                                    </tableCell>
                                    <tableCell>
                                        <textItem>
                                            <text>- </text>
                                        </textItem>
                                        <textItem>
                                            <expression>PageNumber()</expression>
                                        </textItem>
                                        <textItem>
                                            <text> -</text>
                                        </textItem>
                                        <style>
                                            <CSS value="vertical-align:top;text-align:center;width:50%"/>
                                        </style>
                                    </tableCell>
                                    <tableCell>
                                        <textItem>
                                            <expression>AsOfTime()</expression>
                                        </textItem>
                                        <style>
                                            <CSS value="vertical-align:top;text-align:right;width:25%"/>
                                        </style>
                                    </tableCell>
                                </tableRow>
                                <style>
                                    <CSS value="border-collapse:collapse;width:100%"/>
                                </style>
                            </table>
                            <style>
                                <CSS value="padding-top:10px"/>
                            </style>
                        </pageFooter>
                    </page>
                </pageSet>
            </layout>
        </layoutList>
    </report>

```{=html}
</TD>
```
```{=html}
</TR>
```
```{=html}
</TABLE>
```
```{=html}
<table width="100%" border="1" bgcolor="lightgreen">
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<b>`{=html} `<span style="color:SaddleBrown;">`{=html}Section summary:
As Report Specification sticks to XML Rules it is favored for creating
and updating a markup file`</span>`{=html} `</b>`{=html}

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
### Exercise

The end user wants to read the report in Japanese language, so you have
to add a variable for Japanese language.

### Answers

