source: trunk/src/xml2struct.m @ 323

Last change on this file since 323 was 320, checked in by gostiaux, 13 years ago

added xml2struct.m

File size: 539 bytes
Line 
1function s=xml2struct(filename)
2% structure parser, converts numeric character strings into numbers
3
4t=xmltree(filename);
5ss=convert(t)
6s=convert_string(ss);
7
8
9function out=convert_string(s)
10info=whos('s');
11switch info.class
12    case 'struct'
13        names = fieldnames(s);
14        for k=1:length(names)
15            out.(names{k})=convert_string(s.(names{k}));
16        end
17    case 'char'
18        if isempty(regexp(s,'\<\d+\>'))
19            out=s;
20        else
21            out=str2num(s);
22        end
23    otherwise
24        out=s;
25end
26
27   
Note: See TracBrowser for help on using the repository browser.