Line | |
---|
1 | function s=xml2struct(filename) |
---|
2 | % structure parser, converts numeric character strings into numbers |
---|
3 | |
---|
4 | t=xmltree(filename); |
---|
5 | ss=convert(t); |
---|
6 | s=convert_string(ss); |
---|
7 | |
---|
8 | |
---|
9 | function out=convert_string(s) |
---|
10 | info=whos('s'); |
---|
11 | switch 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; |
---|
25 | end |
---|
26 | |
---|
27 | |
---|
Note: See
TracBrowser
for help on using the repository browser.