Range to XML (Schema)
The Range to XML (Schema) function saves an XML file based on the range specified by using an XML Schema defined by the user.
Before this function can be used, an XML Schema needs to be created. To create an XML Schema, copy the sample schema file below and paste it in Notepad. Save this file with the extension XSD.
An element name is needed for each column that is exported. The syntax for element name is <xsd:element name="Time" type="xsd:time"/>. The text “Time” is the column heading and the text “xsd:time” is referring to the data type. Add an element name sequence for each column that is exported and remove any extra element name sequences.
Sample Schema
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Schema">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="Data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Time" type="xsd:time"/>
<xsd:element name="Operator" type="xsd:string"/>
<xsd:element name="Flow" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>Settings | |
|---|---|
Schema | The name of the XML Schema used to perform the export to the XML file. If this is entered without a fully qualified path e.g., C:\XLRproject\Data\mySchema, the schema file must be located in the Data folder of the project. |
Directory | The directory where the XML file is stored. If this is left blank, the text file is stored in the Reports Directory of the current project (as defined in the Project Explorer). If this is not a full path reference, the setting is used as subfolders of the Reports Directory. If any part of the directory does not exist, it is created. This can be a fixed name or cell reference where the cell reference contains the directory. Fixed names can contain XLReporter Name Types like {YYYY}, {MMM}, etc. See the Name Types chapter for the full list of supported keywords. Note that some keywords, such as {DATIM} contain illegal directory characters when evaluated. These keywords cannot be used for the directory. |
File | The name of the XML file to save. If this is left blank, the file is named after the target workbook in the format Workbook.xml. If this is run on demand, the target workbook is the name of the template. Note that keywords for the date and time can be entered for the file name e.g., entering {MMM}_{DD}_{YYYY} will name a file generated on June 1st 2020 as Jun_1_2020.xml. Note that some keywords, such as {DATIM} contain illegal file name characters when evaluated. These keywords cannot be used for the file name. This setting may also be specified as a cell reference. |
Table | The XML table in the schema file to use. If this field is left blank, the first table in the schema file will be used. |
Mode | Overwrite If the XML file exists it is overwritten with the latest data. Append The latest data is appended to the XML file once it exists. |
Example
An analysis application requires 15-minute samples on equipment over the day to monitor how efficiently the plant is operating. That application cannot directly interface with the process historian but can import XML files and provides a schema for the XML structure.
In this case, XLReporter can act as middleware to get the data from the process historian and export the XML file for the analysis application. To accomplish this, a history data group is configured to retrieve the 15-minute samples and a Range to XML management function is configured to export the data to XML.
If the data starts in $B$8:$H$8, the settings are:
Apply To | |
|---|---|
Cell | $B$8:$H$8 |
Direction | Down |
End | All cells are empty |
Setting | Value |
|---|---|
Schema | C:\Analysis\schema.xsd |
Directory | \\FileServer\Analysis |
File | {YYYY}-{MM}-{DD}.xml |
Table | Data |
Mode | Append |
Where FileServer is the name or IP address of the target location.