XML2Structure(filen​ame)

버전 1.0.0.0 (2.2 KB) 작성자: Varoujan
Creates a clean Matlab structure w/ type from input XML
다운로드 수: 235
업데이트 날짜: 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