# The Data Exchange API¶

The following functions you can use within your model, are exposed by the Data Exchange library.

dex::AddMapping(mappingName, mappingFile)

Parses mappingFile to create a mapping called mappingName.

Arguments
• mappingName – the name of the mapping to be created

• mappingFile – the relative path to the mapping file to be parsed.

dex::ReadFromFile(dataFile, mappingName, emptyIdentifiers, emptySets, resetCounters)

Reads data from file dataFile into model identifiers using mapping mappingName. Note that the identifiers used in the included-mapping and write-filter will not be emptied, regardless of the emptyIdentifiers argument. When the mapping contains an the included-mapping or the iterative-existing attributes, emptying sets is likely to cause problems, unless the domain sets referred in these attributes are defined.

Arguments
• dataFile – the relative path to the data file to be read

• mappingName – the name of the mapping to be used

• emptyIdentifiers – indicates whether all identifiers referred in the mapping should be emptied prior to reading the file

• emptySets – indicates whether all domain and range sets referred in the mapping should be emptied prior to reading the file

• resetCounters – indicates whether to reset all counters for iterative-binds-to indices prior to reading the file

dex::WriteToFile(dataFile, mappingName, pretty)

Writes file dataFile from data in model identifiers using mapping mappingName.

Arguments
• dataFile – the relative path to the data file to write to

• mappingName – the name of the mapping to be used for writing

• pretty – indicates whether to use a pretty writer (enhances readibility at the cost of bigger file size)

dex::ReadAllMappings()

Read all mappings contained in the folder Mappings and store all successfully read mappings in the set dex::Mappings.

dex::ReadAnnotations()

Read all dex::Dataset, dex::TableName, and dex::ColumnName annotations specified in the model, and use these annotations to fill the identifiers

• dex::Datasets

• dex::Tables

• dex::Columns

• dex::DatasetTableMapping

• dex::ColumnName

• dex::DatasetTableColumnName

• dex::DatasetTableColumnIndex

• dex::DatasetTableColumnIdentifier

When every table can needs to be included in just a single dataset, you can uniquely specify the dataset-table mapping using annotations only. If tables need to be included in multiple datasets, you can manually modify the identifier dex::DatasetTableMapping to add any table to the datasets you wish to include them in.

dex::GenerateDatasetMappings()

Generate standardized table and Excel sheet mappings based on the dex::Dataset, dex::TableName, and dex::ColumnName annotations. The generated mappings will be stored in the Mappings/Generated subfolder of the project folder. All generated mappings will automatically be added to the set of available mappings, and can be directly used to read and write the standardized JSON, XML, CSV or Excel data sources based on the data exchange annotations.

You can influence how mappings will be generated through:

• dex::DatasetDenseMappings: when a row will be written, determines wither all columns in that row will be written (default), or only the columns containing a non-default value

• dex::DatasetXMLAttributeMappings: determines whether the generated XML format will write all values as XML attribute values (default) or as element values. Indices will always be written as XML attributes.

You can use the generated mappings directly with the functions dex::WriteToFile() and dex::ReadFromFile() as with any manually created mapping.