Changeset 1191 for trunk/src/xml2struct.m
- Timestamp:
- Feb 6, 2026, 5:13:05 PM (2 weeks ago)
- File:
-
- 1 edited
-
trunk/src/xml2struct.m (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/xml2struct.m
r1183 r1191 39 39 catch ME 40 40 errormsg=ME.message; 41 if ~isempty(regexp(ME.message,'Undefined function' ,'once'))||~isempty(regexp(ME.message,'Missing','once'))41 if ~isempty(regexp(ME.message,'Undefined function'))||~isempty(regexp(ME.message,'Missing')) 42 42 errormsg=[errormsg ': package xmltree not correctly installed, reload it from www.artefact.tk/software/matlab/xml']; 43 43 end … … 52 52 end 53 53 end 54 if nargin>1 % additional input vartiable(s) beyond filename, select specified subtrees54 if nargin>1 55 55 for isub=1:nargin-1 56 56 uid_sub=find(t,['/' RootTag '/' varargin{isub}]); … … 58 58 s.(varargin{isub})=[]; 59 59 else 60 tsub=branch(t,uid_sub);61 if ~isempty(get(tsub,1,'contents'))62 ss=convert(tsub);63 s.(varargin{isub})=convert_string(ss);64 end60 tsub=branch(t,uid_sub); 61 if ~isempty(get(tsub,1,'contents')) 62 ss=convert(tsub); 63 s.(varargin{isub})=convert_string(ss); 64 end 65 65 end 66 66 end 67 67 else 68 68 try 69 ss=convert(t);%transform the xmltree object into a Matlab structure.70 s=convert_string(ss);% explore the sub-structures if needed69 ss=convert(t);%transform the xmltree object into a Matlab structure. 70 s=convert_string(ss); 71 71 catch ME 72 72 errormsg=ME.message; … … 85 85 end 86 86 case 'char' 87 % try to convert to number if the char does not correspond to a function (otherwise str2num calls this function as it uses 'eval') 88 if exist(ss,'builtin')||exist(ss,'file')% ss corresponds to the name of a builtin Matlab function or a file 89 out=ss; %reproduce the input string 90 else 91 out=str2num(ss);% convert to number or vector (str2num applied to a fct name executes this fct by 'eval', thus this possibility had to be ruled out above 92 if isempty(out) 87 out=str2double(strsplit(ss));% convert to number or vector (str2num applied to a fct name executes this fct by 'eval', thus this possibility had to be ruled out above 88 if isnan(out) 93 89 sep_ind=regexp(ss,'\s&\s');% check for separator ' & ' which indicates column separation in tables 94 90 if ~isempty(sep_ind) … … 102 98 end 103 99 end 104 end105 100 case 'cell' 106 out= {};%default101 out=cell(numel(ss),1);%default 107 102 check_numeric=zeros(size(ss)); 108 103 for ilist=1:numel(ss) 109 if ~strcmp(ss{ilist},'image') && ~isempty(str2num(ss{ilist}))110 out{ilist,1}=str2 num(ss{ilist});104 if ~isnan(str2double(strsplit(ss{ilist}))) 105 out{ilist,1}=str2double(strsplit(ss{ilist})); 111 106 check_numeric(ilist)=1; 112 107 else … … 129 124 end 130 125 126 131 127
Note: See TracChangeset
for help on using the changeset viewer.
