XML2Structure(filen​ame)

Version 1.0.0.0 (2,2 ko) par Varoujan
Creates a clean Matlab structure w/ type from input XML
235 téléchargements
Mise à jour 23 juin 2015

Afficher la licence

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);

Citation pour cette source

Varoujan (2024). XML2Structure(filename) (https://www.mathworks.com/matlabcentral/fileexchange/51278-xml2structure-filename), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2015a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Structured Data and XML Documents dans Help Center et MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version
1.0.0.0

Added example xml files