Fetching report data from an XML file

You can get the report data from an XML file instead of getting it directly from a database.

The XML file can be a ProcessLevelData file created by a Genero report ( Output to an XML File) which has a special format, or it may be an arbitrary XML file.

From a process level data file

This XML file has a special format, and is created using the Report Writer API function fgl_report_createProcessLevelData File().

The MAIN block of SimpleReport.4gl would change as follows:

  • Provides the name of the data file to be used for the report
  • Use the BDL function fgl_report_runReportFromProcessLevelDataFile to run a report using a data file. The parameters are:
    • The report handler object
    • A String containing the name of the XML file that contains the data
  • This function will replay the report from the file thereby replacing the running of the report (START REPORT, OUTPUT TO REPORT, FINISH REPORT statements).
MAIN

   DEFINE handler om.SaxDocumentHandler, -- report handler 
          data_file String,              -- XML file containing data 
          report_ok boolean              -- return value from function 

    --call the mandatory functions that configure the report  
  IF fgl_report_loadCurrentSettings("myreport.4rp") THEN -- if  the file
                                                         --  loaded OK
    LET handler = fgl_report_commitCurrentSettings()     -- commit the file 
                                                         -- settings
  END IF

  --call the report driver to run the report
  IF handler IS NOT NULL THEN  
    LET data_file = "./OrderReportData.xml"
    LET report_ok = 
           fgl_report_RunReportFromProcessLevelDataFile(handler, data_file) 
  ELSE
    EXIT PROGRAM
  END IF

END MAIN

From other XML files

XML files that were not created by the Reporting API function fgl_report_createProcessLevelData File() can be used as the data source for a Genero report. The file OrderData.xml in the demo sample files of the Reports project is an example of this type of file.

The function fgl_report_runFromXML is used to specify the data source:

This example is from the OrderReportXML.4gl demo program in the Reports project:
MAIN

  IF NOT fgl_report_loadCurrentSettings("Table.4rp") THEN
    EXIT PROGRAM
  END IF

  IF NOT fgl_report_runFromXML("OrderData.xml") THEN
    DISPLAY "RUN FAILED"
    EXIT PROGRAM
  END IF

END MAIN