Changeset 772 for trunk/src/xml2struct.m


Ignore:
Timestamp:
May 9, 2014, 8:33:53 PM (10 years ago)
Author:
sommeria
Message:

manip corrections and cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/xml2struct.m

    r697 r772  
    1717errormsg='';
    1818try
    19     t=xmltree(filename);
     19    t=xmltree(filename);% read the file as an xmltree object t
    2020catch ME
    2121    errormsg=ME.message;
     
    4545    end
    4646else
    47     ss=convert(t);
     47    ss=convert(t);%transform the xmltree object into a Matlab structure.
    4848    s=convert_string(ss);
    4949end
     
    6161    case 'char'
    6262        % 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 blanks
    64             out=str2num(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
    6565        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
    7277                end
    73             else
    74                 out=ss; %reproduce the input string
    7578            end
    7679        end
Note: See TracChangeset for help on using the changeset viewer.