XML2Structure(filen​ame)

Creates a clean Matlab structure w/ type from input XML
235 download
Aggiornato 23 giu 2015

Visualizza la licenza

Given an input xml file, this function returns a clean and typed Matlab structure. The structure elements are automatically named and if the child node tags have 'type' definition, then the data values are converted to appropriate types. The recognized types are:
{'string', 'String', 'char', 'Char'}
{'number', 'Number', 'numeric', 'Numeric', 'double', 'Double', 'single', 'Single'}
{'logical', 'Logical'}
{'vector', 'Vector', 'array', 'Array'}.
The basic functionality comes directly from the Matlab documentation for the built-in 'xmlread' function. It adds additional functionality which I found useful for my applications.
The function will:
a) look for "root" level and if it finds it, it will process it. So, just enclose your xml tags inside <root> ... </root>
b) locate the children of 'root'. The children can have different tags
c) locate the children of the children (i.e., look for 'grandchildren' of 'root'
d) generate structure elements for each grandchild and name the structure fields based on the xml tag of the grandchild
e) if the grandchild tag has 'type' definition, then it will create the fields appropriately.
NOTE - this is NOT a recursive function, so it will not handle anything beyond grandchildren. So, for heavily nested xml structures, it will not work.

See the attached example xml files. Place them in the same folder as the .m file and test as follows:
filename = 'typedXML.xml';
myStruct = XML2Structure(filename);

Cita come

Varoujan (2024). XML2Structure(filename) (https://www.mathworks.com/matlabcentral/fileexchange/51278-xml2structure-filename), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2015a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.0.0.0

Added example xml files