Export to XML
Data stored in the Extensible Markup Language (XML) format allows information systems to share structured data and is a widely-accepted method of storing and transferring data. Logi products use XML files as temporary caches for a variety of purposes and can export Logi report data to XML files.
- About Exporting Data to XML
- Exporting Data Manually
- Exporting Data Automatically
- Saving Other Data as XML Data
- Export to XML Considerations
About Exporting Data to XML
The XML data format is useful because of its relative simplicity and general cross-platform accessibility. XML files are simple text files that can be used to store a variety of data. In the schema used by Logi Info for tabular data, an XML element set represents one data record, each column is identified by an XML attribute name, and its data is the attribute value.
Logi Studio provides Export XML elements that make it easy to export Logi report data into XML
The example above shows report data that has been exported into an XML data file. Note the formatting of the highlighted DateTime data: it's in the ISO 8601 format. Record 1 of the dataset is everything between the first <dtOrders and />. You can give users the ability to export a data manually via user interaction at runtime or choose to automate the export process based on an event or schedule. Manual exports are configured within Report definitions and automated exports are configured within Process definitions.
Here's an example of how to create a report with a link that allows data to be exported manually by the user:
- In your report definition, add an Action.Export XML element as the child of a Label, Image, Button or Chart element, as shown above.
- Below it, add the required Target.XML child element.
- If the data to be exported is part of the current report, you don't need do anything else. Just save your definition and browse your report. It's that simple. The default settings will export the current reports' data.
What happens when the link is clicked? The report's data is exported to a temporary .XML file which is created in your application's rdDownload folder on the web server. The temp file is then opened automatically in your browser (or in whatever tool the .xml file extension has been associated with in the OS). From there, you can save it to a file, if desired.
Note that XML files opened in a browser are usually formatted for easier viewing, which may introduce extraneous characters. If you want to save a "clean" copy of the XML (which is necessary if you want to use the file as a data source later), right-click the displayed XML and select your browser's "View source" option, then save that display to a file.
Only the data from the datalayer is exported; headers, footers, paging, images, etc. from the source report are not exported. Any conditions, filters, aggregations, etc. that have been applied to the datalayer will be reflected in the exported data.
The following table provides explanations for the Target.XML element's attributes, which are all optional:
|Frame ID||Specifies the frame for the target page. Leave blank for the current browser window, or select NewWindow to open a new browser window. You can also specify an existing frame identifier to re-use the same window for each request.|
|ID||Specifies a unique identifier for this element.|
Report Definition File
Specifies the name of the report definition file that contains the data to be exported.
Default: the current report
|Request Forwarding||Specifies whether request variables will be passed to the report definition file that contains the data to be exported. Has no effect if the current report is being exported.|
The temporary files generated during the export are cleaned up automatically over time.
The following example, for Logi Info only, shows how to create a Process task that exports data automatically:
- As shown above, in your Process definition, add a Task element and beneath it a Procedure.Export XML element.
- In the element's Filename attribute, specify the output path and filename, on the web server, for the exported report. The filename should include the ".XML" file extension. The example shown above uses an @Function token to provide the path to the Logi application's application folder on the web server.
- Next, add the required Target.XML element, as shown above.
- In the element's Report Definition File attribute, specify the report that contains the data to be exported. Do not select the CurrentReport option in the list of suggestions as it will notwork.
- Your task will need to be completed, of course, with a Response element to run properly.
What happens when your task runs? The specified report data will be exported to a temporary file in your project folder's rdDownload folder on the web server; then the temp file will be copied to the output file you specified.
If you try to run this task more than once, you'll receive an error. This is due to the fact that Procedure.Export XML will not overwrite an existing file. Adding a Procedure.Delete File element at the beginning of the task will solve this.
An example of a complete task is shown above. Note the use of the @Function again in the Procedure.Delete File element's Filename attribute. Logi products also include an XSL Transform element, which allows you to apply transformations to change the XML output format before the data is exported.
There are situations in which you may, during development, want to capture data from a SQL database or other data source and save it as XML data. For example, it may be desirable to create an XML data file of country names, postal codes, or other static data to be used in an application. Or, it may be useful to work with XML data, without the need for a live database connection. Logi reporting products make it very easy to do this, following these steps:
- Turn on debugging, using the Debug icon in Studio's toolbar or by configuring your application's _Settings definition, General element's Debugger Style attribute to DebuggingLinks and saving the definition.
- Run the Logi report that retrieves the desired SQL data or data from another datasource.
- Click the debug link or icon at the bottom of the report page.
- As shown above, find the View File Stream Data link in the Debugger Trace Report page and click it. This should open the XML in the datalayer in your browser in a data table.
- Click the View raw XML link to view the formatted XML data by itself.
- Right-click in the browser and select View Source. This should open the data in Notepad or some other text editor.
- Save the data in the text editor to a file with an .xml extension.
The data is now ready to be used with Logi applications and can be retrieved using DataLayer.XML.
The following considerations apply to exports to XML file:
- This is a data only export. Only the row-column data in the datalayer is exported. Report headers, footers, and titles, table summary rows and totals, images, etc. are not exported.
- Your computer may associate .xml files with Microsoft Excel, which means that Excel will be launched any time you double-click an .xml file. To view these files outside of Excel, try opening them with Notepad or some other text editor.
- The data exported is the data from the datalayer and the XML attributes will be the column names from the datalayer, not the Data Table Column header text.