Changeset 772 for trunk/src/xml2struct.m
- Timestamp:
- May 9, 2014, 8:33:53 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/xml2struct.m
r697 r772 17 17 errormsg=''; 18 18 try 19 t=xmltree(filename); 19 t=xmltree(filename);% read the file as an xmltree object t 20 20 catch ME 21 21 errormsg=ME.message; … … 45 45 end 46 46 else 47 ss=convert(t); 47 ss=convert(t);%transform the xmltree object into a Matlab structure. 48 48 s=convert_string(ss); 49 49 end … … 61 61 case 'char' 62 62 % try to convert to number if the char does not correspond to a function (otherwise str2num calls this function as it uses 'eval') 63 if ~isempty(regexp(ss,'^(-*\d+\.*\d*\ *)+$')) || ~isempty(regexp(ss,'\d+e(-|+)\d+')) % if the string corresponds to a set of numbers (with possible sign and decimal, or scientific notation) separated by blanks64 out=s tr2num(ss);63 if exist(ss,'builtin')||exist(ss,'file')% ss corresponds to the name of a builtin Matlab function or a file 64 out=ss; %reproduce the input string 65 65 else 66 sep_ind=regexp(ss,'\s&\s');% check for separator ' & ' which indicates column separation in tables 67 if ~isempty(sep_ind) 68 sep_ind=[-2 sep_ind length(ss)+1]; 69 out={}; 70 for icolumn=1:length(sep_ind)-1 71 out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1);% get info between separators as a cell array 66 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 67 if isempty(out) 68 sep_ind=regexp(ss,'\s&\s');% check for separator ' & ' which indicates column separation in tables 69 if ~isempty(sep_ind) 70 sep_ind=[-2 sep_ind length(ss)+1]; 71 out={}; 72 for icolumn=1:length(sep_ind)-1 73 out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1);% get info between separators as a cell array 74 end 75 else 76 out=ss; %reproduce the input string 72 77 end 73 else74 out=ss; %reproduce the input string75 78 end 76 79 end
Note: See TracChangeset
for help on using the changeset viewer.