XML2Structure(filen​ame)

Version 1.0.0.0 (2,2 KB) von Varoujan
Creates a clean Matlab structure w/ type from input XML
235 Downloads
Aktualisiert 23. Jun 2015

Lizenz anzeigen

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

Zitieren als

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

Kompatibilität der MATLAB-Version
Erstellt mit R2015a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Structured Data and XML Documents finden Sie in Help Center und MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.0.0

Added example xml files