XML Data Source

The second data Source is the DTP (Data Tools Project) XML Data Source. The XML Data Source is a driver that allows developers to use XML files as a Data Source.

Let's say we have an XML file containing some entries with employee information. We want to use this XML data file as a Data Source for a report. The XML file looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Employee>
<firstName>John</firstName>
<lastName>Ward</lastName>
<jobTitle>Developer</jobTitle>
</Employee>
<Employee>
<firstName>Bunson</firstName>
<lastName>Honeydew</lastName>
<jobTitle>Professor</jobTitle>
</Employee>
<Employee>
<firstName>Bert</firstName>
<lastName></lastName>
<jobTitle>Fuzzy Muppet</jobTitle>
</Employee>
<Employee>
<firstName>Ernie</firstName>
<lastName></lastName>
<jobTitle>Sidekick</jobTitle>
</Employee>
</Employees>

The XML file is saved as EmployeeData.xml. In order to use this, we need to set up a Data Source. We will follow these steps to achieve this:

  1. Create a new report project called BIRT Book Chapter 5 examples.
    XML Data Source
  2. Create a new report called EmployeeReportCH5.rptDesign. Use the blank template.
    XML Data Source
  3. Under the Data Explorer pane, right- click on Data Sources and select New Data Source.
    XML Data Source
  4. Under the Data Source Type window, select XML Data Source. For the Data Source Name, type dsXMLEmployee.
    XML Data Source
  5. Under the location dialog, select the location where the XML file resides. If available, select a DTD file to verify the schema of the XML file. In our case, the XML file resides under the same workspace location as the Classic Cars examples. Once selected, one can test the file by clicking on Test Connection or you can just click Finish.
    XML Data Source

Now we have a Data Source containing employee information. We will work with this a little more when we start working with datasets. For now, we can hold on to this Data Source for use in a later example.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset