Create the data schema by hand
After you write or modify a Genero report program, you must create the data schema (xsd) file. This file is used by the Genero Report Designer to provide a list of data objects for use in the report design.
The data schema file used by the Genero report program is the XML Schema Definition (xsd) file, which is the standard for defining Extensible Markup Language (XML) documents recommended by the W3C consortium. For more information about XSD, please see the W3C site (www.w3.org).
- It describes an instance document (i.e. an XML file or a data stream record) giving the structure and order of the data that should appear as data input for your application.
- It defines the elements and attributes required by your report to reference the data.
It is recommended to use the Genero Report Writer's Business Application Modeler (BAM), which can generate the data schema (xsd) file automatically from your PHP report application source file (.php). You can also write a generator of schema definition if you wish.
Creating a basic data model for your report application
In a real world situation, the data would be read from another source, and an iterator would read the data into memory and into the data stream one record at a time. Here the data is specified in the code.
...
class Sales extends SerializableRecord
{
public $shopName;
public $zipCode;
public $Date;
public $articleName;
public $category;
public $price;
public $runningTotal;
public function Sales()
{
$shopName="Columbus Arts";
$zipCode="75038";
$Date = date("Y-m-d");
$Salesitems= array();
$Salesitems[count($Salesitems)] = array("Table lamp","Furniture",23.00, null);
$Salesitems[count($Salesitems)] = array("Table lamp","Furniture",267.00, end($Salesitems));
$Salesitems[count($Salesitems)] = array("Office chair","Furniture",155.00, end($Salesitems));
$Salesitems[count($Salesitems)] = array("Grandfather clock","Furniture",329.00, end($Salesitems));
$Salesitems[count($Salesitems)] = array("Scissors","Supplies",19.00, end($Salesitems));
$Salesitems[count($Salesitems)] = array("Measuring tape","Supplies",23.00, end($Salesitems));
$Salesitems[count($Salesitems)] = array("Sun glasses","Travelling",15.95, end($Salesitems));
$Salesitems[count($Salesitems)] = array("Pen knife","Travelling",6.25, end($Salesitems));
$Salesitems[count($Salesitems)] = array("Ornate angel","Art",1.95, end($Salesitems));
}
...
}
Example xsd schema
- A schema element that references the W3C recommended version of
XSD
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- Several subelements identified by the schema's namespace prefix
(xs:element).
- Each element is named to identify it by the data it will contain in the instance
document (i.e. the XML file or the data stream
record)
<xs:element name="zipCode" type="xs:int"/>
- Each element also has a
type
attribute to specify its data type, simple or complex. When elements do not contain child elements, they are defined as simple types, e.g. xs:string, xs:date, xs:decimal, etc. For more information on the data types that are built in to XML schema, see http://www.w3.org and search for "datatypes".
- Each element is named to identify it by the data it will contain in the instance
document (i.e. the XML file or the data stream
record)
<xs:complexType name="sales">
<xs:sequence>
<xs:element name="shopName" type="xs:string" nillable="true"/>
<xs:element name="zipCode" type="xs:int"/>
<xs:element name="day" type="xs:dateTime" nillable="true"/>
<xs:element name="items" type="salesItem" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
These
types specify how data is modeled specifically in our sales application. The sales type in
the example has four child elements: shopname, zipCode, day, and items. The element "items" is itself of type "salesItems", which is another complextype defined
for the list of items sold. The xs:sequence specifies the order these
should appear in the record. As sales items can be zero or unlimited, the attributes
minOccurs="0"
and maxOccurs="unbounded"
specify this for
validation in the instance document. The complete xsd file is shown
below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sales" type="sales"/>
<xs:complexType name="sales">
<xs:sequence>
<xs:element name="shopName" type="xs:string" nillable="true"/>
<xs:element name="zipCode" type="xs:int"/>
<xs:element name="day" type="xs:dateTime" nillable="true"/>
<xs:element name="items" type="salesItem" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="salesItem">
<xs:sequence>
<xs:element name="articleName" type="xs:string" nillable="true"/>
<xs:element name="category" type="xs:string" nillable="true"/>
<xs:element name="price" type="xs:double"/>
<xs:element name="runningTotal" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
The Genero Report Engine does not support optional values;
setting required=true
is mandatory. If a
variable needs to be optional, use
"nillable=true
" and set the variable to
null when there is no value.