source: trunk/src/xml2struct.m @ 434

Last change on this file since 434 was 379, checked in by sommeria, 12 years ago

several bugs corrected
set_object.fig rationalized so that read_set_object is replaced by the rgeneral fct read_GUI.

File size: 1008 bytes
Line 
1% 'xml2struct': read an xml file as a Matlab structure, converts numeric character strings into numbers
2%-----------------------------------------------------------------------
3% function s=xml2struct(filename)
4%
5% OUTPUT:
6% s= Matlab structure corresponding to the input xml file
7%
8% INPUT:
9% filename: name of the xml file
10
11function s=xml2struct(filename)
12t=xmltree(filename);
13ss=convert(t);
14s=convert_string(ss);
15
16
17function out=convert_string(s)
18info=whos('s');
19switch info.class
20    case 'struct'
21        names = fieldnames(s);
22        for k=1:length(names)
23            out.(names{k})=convert_string(s.(names{k}));
24        end
25    case 'char'   
26        if isempty(regexp(s,'^(-*\d+\.*\d*\ *)+$'))% if the string contains a set of numbers (with possible sign and decimal) separated by blanks
27            out=s;
28        else
29            out=str2num(s);
30        end
31    case 'cell'
32        for ilist=1:numel(s)
33            out(ilist,:)=str2num(s{ilist});
34        end
35    otherwise
36        out=s;
37end
38
39   
Note: See TracBrowser for help on using the repository browser.