XML2Structure(filen​ame)

版本 1.0.0.0 (2.2 KB) 作者: Varoujan
Creates a clean Matlab structure w/ type from input XML
235.0 次下载
更新时间 2015/6/23

查看许可证

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

引用格式

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

MATLAB 版本兼容性
创建方式 R2015a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Structured Data and XML Documents 的更多信息
标签 添加标签

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

Added example xml files