Table of Contents
Data sources are used to create dynamic content that is updated from external data sources as described in the overview in Section 6.4, “Data Source”.
Data sources are shown in the Demorize Editor under the Data Sources category in the Project view. A data source in the Project view means a connection to the source from which to collect data. The data source definition itself does not collect any data, it just specifies how the connection shall be established. A data item, which is added to a data source, is needed in order to specify what data to extract from the data source. A data source may contain many data items in order to access different data chunks from the data source. To make an example, a data source may be a connection to a database while the data items that are added to the data source definition specifies which SQL queries to make against the database. Each of these data items are given a name that can be referenced by for example text or graph objects in a scene in order to present the data that is retrieved from the database. Some data sources, such as the RSS data source, have implicit data items that are defined by the RSS feed itself. In these cases the user will not need to add the data items herself.
A new data source is added from the context menu for the Data Sources category item in the Project view or from the Insert tab in the application menu. The properties for the new data source item must be edited before it can be used. A data source contains the following properties:
Example 16.2. Example of a Lua data source script
-- Example script data source written in the Lua language (http://www.lua.org) function Update() end function GetFieldNames() return { "Increase", "Square" } end function GetRecordCount() return 10 end function GetValue(record, field) if field == "Increase" then return tostring(record + 1) elseif field == "Square" then return tostring(record * record) end return "" end
Data Items are added to Data Sources from the context menu of a data source. The data item define what data to retrieve from the data source. There can be many data items added to a single data source, which each can collect different data from the source. The data items works differently for each of the data source types and the Query property of the data item for the different data source types shall be defined as follows:
Example 16.5. Example of the XPath property for an XML data item
For an XML file looking like this:
<?xml version="1.0" encoding="UTF-8"?> <catalog> <book id="bk101"> <author>Right, Ronald</author> <title>The ways of my life</title> <genre>Bibliography</genre> <price>74.95</price> <publish_date>2014-10-01</publish_date> <description> An in-depth look at how I succeeded in life. </description> </book> <book id="bk102"> <author>Thrall, Kim</author> <title>Layers of Shields</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2010-12-16</publish_date> <description> A weapon smith meets a powerful wizard and forms an alliance. </description> </book> <book id="bk103"> <author>Merit, Eva</author> <title>Elves Ascending</title> <genre>Fantasy</genre> <price>4.95</price> <publish_date>2015-03-16</publish_date> <description> On her tenth birthday, a young girl starts to experience something strange with her closet. </description> </book> </catalog>
Extract data from the XML by typing one of the following examples into the XPath property:
Example 16.6. Example of a direct file reference from a folder data source
A file named MyPicture.jpg can be referenced from a folder data source named MyFileFolderSource using the following data reference string:
@{MyFileFolderSource:MyPicture.jpg}