Connectors: Importing and Exporting XML

Because XML files are a very structured file format, they are not included in the topic on text file imports and exports. XML files are very flexible and can describe almost any type of data; the Connector configuration required to read or write an XML file requires a little more explanation and effort to understand. Here is a simple example of an XML file that describes Room data in the figure below. 

In this example, the Room data (records) are nested in an XML element (<Record>) and all of the records in the file are in a root XML element (<Data>).  In order to inform the Connector how to read this file, you must configure the path within this file to the records; think of it as the table in a database.  With that in mind, you specify this path, called an XPath in XML, to the records in the Remote Source (Table, XML, etc.) property of the Connector. The XPath entry for the XML file above is "Data/Record."

Now that the Connector knows where the data records in this file are located, you must configure each field in the record in the Define Connector Fields tab.  XML files store data as either Element text or as an Attribute to the Element.  In the example file above, the Building, Floor and Room Codes ("HQ", "21" and "000") are listed as Element text for the <Building>, <Floor> and <Room> elements, whereas the Area, Division and Department values are listed as Attributes of the <Room> element.  For each field that you want to read or write in the record, you must specify the XPath relative to the record XPath already specified above. The image below shows the field mapping in the Example XML Connector.  Note that Attribute values in XPaths are prefixed with an "@" symbol.  As pictured below, these field-level XPath statements are mapped to fields in the Archibus Rooms table and configured with standard field-level processing rules.

When Exporting XML data, you must supply an additional piece of data to the Connector for processing the XML output:  a template XML string for one record in the file. For example, to create an export of room data in the format pictured in the XML file above, you must specify a prototype or template XML structure for one record; then in the Connector Field Mapping, you specify the XPATH within the template for each field.  The XML string below is an example Connector XML Template.

<Record>
<Building/>
<Floor/>
<Room Area="" Division="" Department=""/>
</Record>

The Connector Field Mapping for this example is pictured below.  Notice that there are slight differences in the XPATH statements for the Import and Export Connector examples.  The important point to note is that the XPATH must match the template XML provided in the Connector configuration.