xmlstr = generateXML(in)
Output the variable "in" as an XML string; intended for exporting structures for later import in a database.
It features the following specificities:
a) Cell-array and substructure linking:
Most database systems generate new tables for each substructure (or cell array, that are sort of structures also) present in the XML file (e.g. Access). Importing the XML results in several tables without relations...
With generateXML, when cell arrays or sub-structures are encountered, a "foreign key" is added in the parent object. The child cell array or structure recieve a corresponding "primary key". This allows keeping the relationships...
b) Blowing up the matrices:
Most database systems cannot import a matrix in one step. Each element is a single number, and in the best case, the whole matrix is imported as a long, space-separated string. With generateXML, matrices are devided into single elements, which each get a new label (e.g. mymatrix_1, mymatrix_2, ...). Thus matrices are correctly imported (with one value per column in the record).
This XML format generates a HUGE overhead, mostly because of the matrix blow-up, and is probably not usable when the structure contains very large matrices. It is however efficient for rather intrigate structures containing relatively small datasets. If you do not intend to import the data in a database, but only to save in human-readable form the data for further use in MATLAB or other custom software, it is advised to use the more efficient XML Toolbox by Marc Molinari, available on this website (link in Acknoledgements below). On top of it, generateXML is a one-way function and it does not feature an import fonctionality [yet]... to reimport data, or to work on the resulting database, use SQL and the CSE SQL Library, available on this website (link in Acknoledgements below).
The data types supported are: char, numeric (also complex), struct, cell, logical/boolean only. Sparse matrices are not supported.
Laurent Cavin (2023). generateXML (https://www.mathworks.com/matlabcentral/fileexchange/6038-generatexml), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!