Home > . > editxml.m

# editxml

## PURPOSE

'editxml': function for editing xml files using a xml schema (associated with the GUI editxml.fig)

## SYNOPSIS

function varargout = editxml(varargin)

## DESCRIPTION

    'editxml': function for editing xml files using a xml schema (associated with the GUI editxml.fig)
    ------------------------------------------------------------------------
     function heditxml=editxml(inputfile)

    OUTPUT: heditxml: graphic handle of the GUI

    INPUT: inputfile:  name of an xml file

    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
         This file is part of the toolbox UVMAT.

         UVMAT is free software; you can redistribute it and/or modify
         it under the terms of the GNU General Public License as published by
         the Free Software Foundation; either version 2 of the License, or
         (at your option) any later version.

         UVMAT is distributed in the hope that it will be useful,
         but WITHOUT ANY WARRANTY; without even the implied warranty of
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
         GNU General Public License (file UVMAT/COPYING.txt) for more details.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

## CROSS-REFERENCE INFORMATION

This function calls:

- ListDir 'ListDir': scan the structure of the directory tree (for dataview.m)
- cell2tab 'cell2tab': transform a Matlab cell in a character array suitable for display in a table
- dataview TEST 'dataview': function for scanning directories in a campaign (TEST)
- read_xls 'read_xls': function for reading and displaying Excel files
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
- warndlg_uvmat 'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure

This function is called by:

- civ 'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
- civ_3D 'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume
- dataview TEST 'dataview': function for scanning directories in a campaign (TEST)
- read_xls 'read_xls': function for reading and displaying Excel files
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

## SUBFUNCTIONS

- function editxml_OpeningFcn(hObject, eventdata, handles, varargin)
- function varargout = editxml_OutputFcn(hObject, eventdata, handles)
- function list_element_Callback(hObject, eventdata, handles)
- function move_up_Callback(hObject, eventdata, handles)
- function element_value_Callback(hObject, eventdata, handles)
- function browser_Callback(hObject, eventdata, handles)
- function CurrentFile_Callback(hObject, eventdata, handles)
- function [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,nodeinput)
- function [element,subelem]=get_xml(t,path,xs_element,node,xs_subelem)
- function update_list(handles,path,xs_element,element,node,xs_subelem,subelem)
- function SAVE_Callback(hObject, eventdata, handles)
- function t=set_element(t,RootUid,node,key,value)
- function element_attr_val_Callback(hObject, eventdata, handles)
- function ADD_Callback(hObject, eventdata, handles)
- function [Data,testsimple]=displ_xml(handles,t,root_uid,DataIn,heditxml)
- function update_ref_list(hh,xs_element,element,node,xs_subelem,subelem)
- function replicate_Callback(hObject, eventdata, handles)
- function HELP_Callback(hObject, eventdata, handles)
- function Export_Callback(hObject, eventdata, handles)
- function pushbutton9_Callback(hObject, eventdata, handles)

## SOURCE CODE

    0001 %'editxml': function for editing xml files using a xml schema (associated with the GUI editxml.fig)
    0002 %------------------------------------------------------------------------
    0003 % function heditxml=editxml(inputfile)
    0004 %
    0005 %OUTPUT: heditxml: graphic handle of the GUI
    0006 %
    0007 %INPUT: inputfile:  name of an xml file
    0008 %
    0009 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0010 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0011 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0012 %     This file is part of the toolbox UVMAT.
    0013 %
    0014 %     UVMAT is free software; you can redistribute it and/or modify
    0015 %     it under the terms of the GNU General Public License as published by
    0016 %     the Free Software Foundation; either version 2 of the License, or
    0017 %     (at your option) any later version.
    0018 %
    0019 %     UVMAT is distributed in the hope that it will be useful,
    0020 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0021 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0022 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0023 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0024
    0025 function varargout = editxml(varargin)
    0026
    0027 % Begin initialization code - DO NOT EDIT
    0028 gui_Singleton = 1;
    0029 gui_State = struct('gui_Name',       mfilename, ...
    0030                    'gui_Singleton',  gui_Singleton, ...
    0031                    'gui_OpeningFcn', @editxml_OpeningFcn, ...
    0032                    'gui_OutputFcn',  @editxml_OutputFcn, ...
    0033                    'gui_LayoutFcn',  [] , ...
    0034                    'gui_Callback',   []);
    0035 if nargin & isstr(varargin{1})
    0036     gui_State.gui_Callback = str2func(varargin{1});
    0037 end
    0038
    0039 if nargout
    0040     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    0041 else
    0042     gui_mainfcn(gui_State, varargin{:});
    0043 end
    0044 % End initialization code - DO NOT EDIT
    0045
    0046
    0047 % --- Executes just before editxml is made visible.
    0048 function editxml_OpeningFcn(hObject, eventdata, handles, varargin)
    0049 % This function has no output args, see OutputFcn.
    0050 % hObject    handle to figure
    0051 % eventdata  reserved - to be defined in a future version of MATLAB
    0052 % handles    structure with handles and user data (see GUIDATA)
    0053 % varargin   command line arguments to editxml (see VARARGIN)
    0054
    0055 % set(handles.replicate,'String',['copy';'<---'])
    0056 if nargin
    0057     CurrentFile=varargin{1}
    0058 else
    0059     CurrentFile=[];
    0060 end
    0061 % if exist('varargin') & length(varargin)>=1
    0062 %     CurrentFile=cell2mat(varargin{1});
    0063 % else
    0064 %     CurrentFile=[];
    0065 % end
    0066 % Choose default command line output for editxml
    0067 handles.output = hObject;
    0068 % set(hObject,'Units','pixel')
    0069 if exist(CurrentFile,'file')
    0070     [PathName,Nme,FileExt]=fileparts(CurrentFile);
    0071     if isequal(FileExt,'.xls')
    0072         DataIn.hfig_xls=read_xls(CurrentFile);% DataIn.hfig_xls=handle of the Excel display figure
    0073         DataIn.CurrentUid=1;
    0074         figpos=get(hObject,'Position');%position of the editxml interface
    0075         figposunit=get(hObject,'Units');%unity used to indicate position
    0076         newfigpos=[figpos(1)-0.5*figpos(3) figpos(2) figpos(3) figpos(4)];
    0077         set(DataIn.hfig_xls,'Units',figposunit)
    0078         set(DataIn.hfig_xls,'Position',newfigpos); %set position of the Excel display figure
    0079         set(hObject,'UserData',DataIn)
    0080     else
    0081         set(handles.CurrentFile,'String',CurrentFile)
    0082         CurrentFile_Callback(hObject, eventdata, handles)
    0083     end
    0084 end
    0085 % Update handles structure
    0086 guidata(hObject, handles);
    0087
    0088 %----------------------------------------------------------------
    0089 % --- Outputs from this function are returned to the command line.
    0090 function varargout = editxml_OutputFcn(hObject, eventdata, handles)
    0091 % varargout  cell array for returning output args (see VARARGOUT);
    0092 % hObject    handle to figure
    0093 % eventdata  reserved - to be defined in a future version of MATLAB
    0094 % handles    structure with handles and user data (see GUIDATA)
    0095
    0096 % Get default command line output from handles structure
    0097 varargout{1} = handles.output;
    0098
    0099
    0100 % --- Executes on selection change in list_element.
    0101 function list_element_Callback(hObject, eventdata, handles)
    0102 global t xs t_ref
    0103 CurrentFile=get(handles.CurrentFile,'String');
    0104 bla=get(hObject,'String');
    0105 ind=get(hObject,'Value');
    0106 list=get(hObject,'UserData');
    0107 NewRootUid=list.uid(ind);
    0108 heditxml=get(hObject,'Parent');
    0109 DataIn=get(heditxml,'UserData');
    0110 if ~isempty(xs)
    0111     xs_node=list.xs_uid(ind);%xs_node of the subelement #ind
    0112     [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node);
    0113     [element,subelem]=get_xml(t,path,xs_element,NewRootUid,xs_subelem);
    0114     update_list(handles,path,xs_element,element,NewRootUid,xs_subelem,subelem);
    0115     if xs_element.subtest
    0116         DataIn.CurrentUid=[DataIn.CurrentUid NewRootUid];%record new current uid
    0117         DataIn.xs_CurrentUid=[DataIn.xs_CurrentUid xs_node];%record the new curent schema uid
    0118     end
    0119
    0120 %     %update the import file display
    0121 %     if isfield(DataIn,'h_ref')&ishandle(DataIn.h_ref)
    0122 %         tag0_ref=find(t_ref,['/' path '/' xs_element.key]);
    0123 %         node_ref=list.index(ind);
    0124 %         if length(tag0_ref)<node_ref
    0125 %             node_ref=length(tag0_ref);
    0126 %         end
    0127 %         [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,node_ref,xs_subelem);
    0128 %         update_ref_list(DataIn.h_ref,xs_element,ref_element,node_ref,xs_subelem,ref_subelem);
    0129 %     end
    0130 set(get(hObject,'Parent'),'UserData',DataIn);
    0131 else%no schema
    0132     [DataIn,testsimple]=displ_xml(handles,t,NewRootUid,DataIn,get(hObject,'parent'));
    0133     if ~testsimple
    0134         DataIn.CurrentUid=[DataIn.CurrentUid NewRootUid];%record new current uid
    0135         set(get(hObject,'Parent'),'UserData',DataIn);
    0136     end
    0137 end
    0138
    0139 %-------------------------------------------------
    0140 % --- Executes on button press in move_up.
    0141 function move_up_Callback(hObject, eventdata, handles)
    0142 global t xs t_ref
    0143 set(handles.export_list,'Value',1);%
    0144 set(handles.export_list,'String','');% empty the export list
    0145 CurrentFile=get(handles.CurrentFile,'String');
    0146 CurrentElement=get(handles.CurrentElement,'String');
    0147 heditxml=get(handles.move_up,'parent');
    0148 test_root=0;
    0149 DataIn=get(heditxml,'UserData');
    0150 if isfield(DataIn,'CurrentUid')&length(DataIn.CurrentUid)>1
    0151     nodeup=DataIn.CurrentUid(end-1);
    0152     DataIn.CurrentUid(end)=[];
    0153 else
    0154     nodeup=[];
    0155 end
    0156 if isempty(xs)
    0157     if isempty(nodeup)
    0158         test_root=1;
    0159     else
    0160         DataIn=displ_xml(handles,t,nodeup,DataIn,heditxml);
    0161     end
    0162 else
    0163     xs_nodeup=[];
    0164 %     if isfield(DataIn,'xs_UpUid')
    0165     if isfield(DataIn,'xs_CurrentUid')&length(DataIn.xs_CurrentUid)>1
    0166 %         xs_nodeup=DataIn.xs_UpUid
    0167         xs_nodeup=DataIn.xs_CurrentUid(end-1);
    0168         DataIn.xs_CurrentUid(end)=[];%uid of the root element in the schema
    0169     end
    0170     if isempty(xs_nodeup)
    0171         test_root=1;
    0172     else
    0173         [xs_nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_nodeup);
    0174         [element,subelem]=get_xml(t,path,xs_element,nodeup,xs_subelem);
    0175         update_list(handles,path,xs_element,element,nodeup,xs_subelem,subelem);
    0176         %update the import file display
    0177         if isfield(DataIn,'h_ref')&ishandle(DataIn.h_ref)
    0178             [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,nodeup,xs_subelem);
    0179             update_ref_list(DataIn.h_ref,xs_element,ref_element,nodeup,xs_subelem,ref_subelem);
    0180         end
    0181     end
    0182     set(get(hObject,'parent'),'UserData',DataIn);
    0183 end
    0184 if test_root% we are a the root,
    0185     testupfile=0;
    0186     DataIn=get(get(hObject,'parent'),'UserData');
    0187     if isfield(DataIn,'UpFile')&~isempty(DataIn.UpFile)
    0188         [UpPath,UpName,UpExt]=fileparts(DataIn.UpFile{1});
    0189         if isequal(UpExt,'.xml')
    0190             set(handles.CurrentFile,'String',DataIn.UpFile{1})
    0191             CurrentFile_Callback(handles.CurrentFile,[],handles)
    0192             testupfile=1;
    0193             DataIn.UpFile{1}={};
    0194         end
    0195     end
    0196     if ~testupfile  %open the browser
    0197         RootPath=fileparts(CurrentFile);
    0198             [FileName, PathName]=uigetfile( ...
    0199                {'*.xml', '(*.xml)';
    0200                 '*.xml',  '.xml files '; ...
    0201                 '*.*',  'All Files (*.*)'}, ...
    0202                 'Pick a file',RootPath); %file browser
    0203             fileinput_new=fullfile(PathName,FileName);
    0204             set(handles.CurrentFile,'String',fileinput_new)
    0205             CurrentFile_Callback(handles.CurrentFile,[],handles)
    0206      end
    0207 end
    0208 set(heditxml,'UserData',DataIn);
    0209 %---------------------------------------------------------
    0210 %edit element value
    0211 function element_value_Callback(hObject, eventdata, handles)
    0212 %----------------------------------------------------------
    0213 global t xs
    0214 if isequal(get(handles.element_value,'ForegroundColor'),[0.7 0.7 0.7])
    0215     return% edit element desactivated (grey display)
    0216 end
    0217 list_enum=get(handles.element_value,'String');
    0218 list_index=get(handles.element_value,'Value');
    0219 if iscell(list_enum)
    0220     value=list_enum{list_index};
    0221 else
    0222     value=list_enum;
    0223 end
    0224 heditxml=get(handles.element_value,'Parent');
    0225 DataIn=get(heditxml,'UserData');
    0226 %create the current root element if needed
    0227 LengthElement=length(DataIn.CurrentUid);
    0228 FilledUid=find(DataIn.CurrentUid~=0);
    0229 LengthFilled=FilledUid(end);
    0230 for irank=LengthFilled+1:LengthElement
    0231     attrib=attributes(xs,'get',DataIn.xs_CurrentUid(irank),1);
    0232     [t,DataIn.CurrentUid(irank)]=add(t,DataIn.CurrentUid(irank-1),'element',attrib.val);
    0233 end
    0234 node_element=get(handles.element_value,'UserData');
    0235 element_key=get(handles.element_key,'String');
    0236 t=set_element(t,DataIn.CurrentUid(end),node_element,element_key,value);
    0237
    0238 set(heditxml,'UserData',DataIn)
    0239 %update the current listing
    0240 [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid(end));
    0241 [element,subelem]=get_xml(t,path,xs_element,DataIn.CurrentUid(end),xs_subelem);
    0242 element_index=get(handles.list_element,'Value');
    0243 update_list(handles,path,xs_element,element,DataIn.CurrentUid(end),xs_subelem,subelem);
    0244 set(handles.list_element,'Value',element_index);
    0245
    0246 %
    0247 % % --- Executes on button press in inport_file.
    0248 % function inport_file_Callback(hObject, eventdata, handles)
    0249 % CurrentFile=get(handles.RefFile,'String');
    0250 % if isempty(CurrentFile)|isequal(CurrentFile,'')
    0251 %     CurrentFile=get(handles.CurrentFile,'String')
    0252 % end
    0253 % [FileName, PathName]=uigetfile( ...
    0254 %        {'*.xml', '(*.xml)';
    0255 %         '*.xml',  '.xml files '; ...
    0256 %         '*.*',  'All Files (*.*)'}, ...
    0257 %         'Pick a file',CurrentFile); %file browser
    0258 % fileinput=fullfile(PathName,FileName);
    0259 % sizf=size(fileinput);
    0260 % if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end% keep only character strings as input file name
    0261 % if exist(fileinput,'file')
    0262 %    set(handles.RefFile,'Visible','on')
    0263 %    set(handles.replicate,'Visible','on')
    0264 %    set(handles.RefFile,'String',fileinput)
    0265 %    RefFile_Callback(handles.RefFile, eventdata, handles)
    0266 % end
    0267
    0268
    0269 %------------------------------------------------------
    0270 % --- Executes on button press in browser.
    0271 function browser_Callback(hObject, eventdata, handles)
    0272 %-------------------------------------------------------
    0273 heditxml=get(hObject,'parent');%handle of the interface figure
    0274 DataIn=get(heditxml,'UserData');%get the current input xml file
    0275 CurrentFile=get(handles.CurrentFile,'String');
    0276 DataIn.Schema=[];%schema input file put to [] by default
    0277 [FileName, PathName]=uigetfile( ...
    0278        {'*.xml;*.xls','(*.xml,*.xls)';
    0279         '*.xml',  '.xml files '; ...
    0280         '*.xls',  '.xls files '; ...
    0281         '*.*',  'All Files (*.*)'}, ...
    0282         'Pick a file',CurrentFile); %file browser
    0283 CurrentFile=fullfile(PathName,FileName);
    0284 sizf=size(CurrentFile);
    0285 if (~ischar(CurrentFile)|~isequal(sizf(1),1)),return;end% keep only character strings as input file name
    0286 if exist(CurrentFile,'file')
    0287 %     set(handles.CurrentAttributes,'UserDataIn',PathName); %store the path to the xml file
    0288     [CurPath,CurName,CurExt]=fileparts(CurrentFile);
    0289     if isequal(CurExt,'.xls')
    0290         if isfield(DataIn,'hfig_xls')&ishandle(DataIn.hfig_xls)
    0291             [hfig_xls]=read_xls(CurrentFile,DataIn.hfig_xls);
    0292         else
    0293             [hfig_xls]=read_xls(CurrentFile);
    0294         end
    0295         figpos=get(heditxml,'Position');
    0296         newfigpos=[figpos(1)-0.25*figpos(3) figpos(2) 0.5*figpos(3) 0.5*figpos(4)];
    0297         set(hfig_xls,'Position',newfigpos)
    0298     else
    0299         set(handles.CurrentFile,'String',CurrentFile)
    0300         CurrentFile_Callback(hObject, eventdata, handles)
    0301      end
    0302 end
    0303
    0304 %------------------------------------
    0305 function CurrentFile_Callback(hObject, eventdata, handles)
    0306 global t xs
    0307 CurrentFile=get(handles.CurrentFile,'String');
    0308 heditxml=get(handles.CurrentFile,'parent');%handles of the inteface
    0309 DataIn=get(heditxml,'UserData');
    0310 t=xmltree(CurrentFile);%open the xml file
    0311 head_element=get(t,1);
    0312 if ~isfield(head_element,'name') | ~isfield(head_element,'attributes')
    0313     warndlg_uvmat('root element of the .xml file not in correct format','ERROR')
    0314 end
    0315 head_name=head_element.name;
    0316 head_attr=head_element.attributes;% attribute of root gives the name of the associated schema
    0317 xstest=0;
    0318 for iattr=1:length(head_attr)
    0319     if isequal(head_attr{iattr}.key,'xmlns:xsi')& isequal(head_attr{iattr}.val,'none')%no schema to read
    0320          xs=[];
    0321 %          xstest=1;
    0322     end
    0323     if isequal(head_attr{iattr}.key,'xsi:noNamespaceSchemaLocation') & exist(head_attr{iattr}.val,'file')
    0324         DataIn.Schema=head_attr{iattr}.val;
    0325         xs=xmltree(DataIn.Schema);%open the associated schema file
    0326         xstest=1;
    0327     end
    0328 end
    0329 if xstest==0  %look for the corresponding schema in the directory PARAM_LINUX.xml or PARAM_WIN.xml
    0330     head_name=get(t,1,'name');
    0331     %Path to shemas:
    0332     path_uvmat=which('editxml');% check the path detected for source file uvmat
    0333     path_UVMAT=fileparts(path_uvmat); %path to UVMAT
    0334     if isunix
    0335         xmlparam=fullfile(path_UVMAT,'PARAM_LINUX.xml')
    0336         if exist(xmlparam,'file')
    0337             tparam=xmltree(xmlparam);
    0338             sparam=convert(tparam);
    0339             if isfield(sparam,'SchemaPath')
    0340                 schemapath=[fullfile(sparam.SchemaPath,head_name) '.xsd']
    0341             end
    0342         end
    0343 %         schemapath=['/coriolis/papillon/data/civbin/XML_SCHEMAS/' head_name '.xsd']%current dir for schema
    0344     else
    0345         xmlparam=fullfile(path_UVMAT,'PARAM_WIN.xml')
    0346         if exist(xmlparam,'file')
    0347             tparam=xmltree(xmlparam);
    0348             sparam=convert(tparam)
    0349             if isfield(sparam,'SchemaPath')
    0350                 schemapath=[fullfile(sparam.SchemaPath,head_name) '.xsd']
    0351             end
    0352         end
    0353 %         schemapath=['\\Papillon\data\civbin\XML_SCHEMAS\' head_name '.xsd']%current dir for schemas
    0354     end
    0355     if exist(schemapath,'file')
    0356         xs=xmltree(schemapath);
    0357     else
    0358         warndlg_uvmat(['The xml schema for ' CurrentFile ' is unknown, check the schema path set in the xml file PARAM'],'ERROR')
    0359         [FileName, PathName]=uigetfile( ...
    0360        {'*.xsd', '(*.xsd)';
    0361         '*.xsd',  '.xsd files '; ...
    0362         '*.*',  'All Files (*.*)'}, ...
    0363         ['Pick a .xsd schema'] ,schemapath); %file browser
    0364         if ischar(PathName)&ischar(FileName)& exist(fullfile(PathName,FileName),'file')
    0365             DataIn.Schema=fullfile(PathName,FileName);
    0366             xs=xmltree(DataIn.Schema);%open the associated schema file
    0367         else
    0368             xs=[];
    0369         end
    0370     end
    0371 end
    0372 DataIn.CurrentUid=1;
    0373 if isempty(xs)
    0374     displ_xml(handles,t,1,DataIn,get(hObject,'parent'));%no associated schema, default  display of the xml file
    0375 %    set(handles.inport_file,'Visible','off')
    0376 %    set(handles.RefFile,'Visible','off')
    0377 else
    0378     DataIn.xs_CurrentUid=find(xs,'/xs:schema/xs:element');%uid of the root element in the schema
    0379     [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid);%scan the schema at the root level
    0380     [element,subelem]=get_xml(t,path,xs_element,1,xs_subelem);% read the corresponding xml data
    0381     update_list(handles,path,xs_element,element,1,xs_subelem,subelem);%update the display of information on the interface
    0382    % set(handles.inport_file,'Visible','on')
    0383    % set(handles.RefFile,'Visible','on')
    0384 end
    0385 set(heditxml,'UserData',DataIn);%store the new input xml file name
    0386
    0387 %-------------------------------------------------------
    0388 %  function scan_schema: read the xml schema xs
    0389 %--------------------------------------------------------
    0390 %OUTPUT:
    0391 %nodeup: parent node of nodeinput
    0392 %path: path to nodeinput in the tree
    0393 %xs_element: element corresponding to nodeinput
    0394     %xs_element.uid, =tag of the element in the schema (=nodeinput)
    0395     %xs_element.key: key label of nodeinput
    0396     %xs_element.type: type of data contained in the element
    0397     %xs_element.annot: annotation of nodeinput
    0398     %xs_element.attrib: list of accepted attributes keys for xs_element
    0399     %xs_element.enum: enumeration, list of accepted values for nodeinput
    0400     %xs_element.subtest: =1 if the element contains subelements in the schema, 0 else
    0401
    0402 %xs_subelement(k): subelement #k of xs_element
    0403     %xs_subelem(k).node: node number in the schema
    0404     %xs_subelem(k).key: key name of the element
    0405     %xs_subelem(k).testsub: =1 if element contains subelements, 0 else
    0406     %xs_subelem(k).minOccurs: =0 for a non mandatory element, =1 else
    0407     %xs_subelem(k).maxOccurs
    0408 %
    0409 %INPUT:
    0410 %xs: schema xml tree
    0411 %nodeinput: tag of the current root element in the schema
    0412 function [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,nodeinput)
    0413 nodeup=[];
    0414 path=[];
    0415 xs_element.key=[];
    0416 xs_element.type=[];
    0417 xs_element.annot=[];
    0418 xs_element.attrib=[];
    0419 xs_element.subtest=0;
    0420 xs_element.enum={};
    0421 xs_subelem=[];%default
    0422 % get default nodeinput (root of the file) if not defined
    0423 if ~exist('nodeinput') | isempty(nodeinput)% we start at the root
    0424     node=find(xs,'/xs:schema/xs:element');%description of the root element
    0425 else
    0426     node=nodeinput;
    0427 end
    0428 xs_element.uid=node;
    0429 %get the key name and element_type of the element
    0430 node_content=get(xs,node);
    0431 if isempty(node_content),return,end;
    0432 if ~isempty(node_content) & isfield(node_content,'attributes')
    0433     attrib=node_content.attributes;
    0434     for iattr=1:length(attrib)
    0435         struct=attrib{iattr};
    0436         if isequal(struct.key,'name')
    0437             xs_element.key=struct.val; % read element key name
    0438         elseif isequal(struct.key,'type')
    0439             xs_element.type=struct.val; % read element key name
    0440         end
    0441     end
    0442 end
    0443
    0444 %get the parent node of nodeinput
    0445 if ~isempty(node_content)
    0446     nodeup=get(xs,node,'parent');%move up to the parent in the tree
    0447     if ~isempty(nodeup)
    0448         nodeup=get(xs,nodeup(1),'parent');%move up to the parent in the tree
    0449         if isequal(nodeup,[])
    0450             %OUVRIR FICHIER AMONT
    0451             up=0;
    0452         else
    0453             nodeup=get(xs,nodeup(1),'parent');%move up to the parent in the tree
    0454         end
    0455     end
    0456 end
    0457 %get the path to 'nodeinput' in the schema
    0458 up=1;
    0459 path=[];
    0460 if ~isempty(nodeup)
    0461     attrib=attributes(xs,'get',nodeup,1);
    0462     path=attrib.val;
    0463     nodeup2=nodeup;
    0464     while up==1;
    0465         nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree
    0466         nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree
    0467         if isempty(nodeup2)
    0468             up=0;
    0469         else
    0470             nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree
    0471             if isempty(nodeup2)
    0472                 up=0;
    0473             else
    0474                 attrib=attributes(xs,'get',nodeup2,1);
    0475                 path=[attrib.val '/' path];
    0476             end
    0477         end
    0478     end
    0479 end
    0480
    0481 %explore the subtree in the schema file
    0482 node1=children(xs,node); %find the children of the root element
    0483 test_sub=0; %no subtree in the .xml file by default
    0484 comment='';
    0485 element={};
    0486 minOccurs={};
    0487 maxOccurs={};
    0488 testsub={};
    0489 list_menu={};
    0490 text={};
    0491 if ~isempty(node1)
    0492   for i=1:length(node1)
    0493     nodename1=get(xs,node1(i),'name');
    0494     node2=children(xs,node1(i));
    0495     if isequal(nodename1,'xs:annotation')
    0496          for j=1:length(node2)
    0497             nodename2=get(xs,node2(j),'name');
    0498             if isequal(nodename2,'xs:documentation')
    0499                 node3=children(xs,node2(j));
    0500                 xs_element.annot=get(xs,node3,'value');%read annotation
    0501             end
    0502         end
    0503     % pour les elements
    0504     elseif isequal(nodename1,'xs:simpleType')
    0505         for j=1:length(node2)
    0506             nodename2=get(xs,node2(j),'name');
    0507             if isequal(nodename2,'xs:restriction')
    0508                 node3=children(xs,node2(j));
    0509                 for k=1:length(node3)
    0510                     nodename3=get(xs,node3(k),'name');
    0511                     if isequal(nodename3,'xs:enumeration')
    0512                         node3_content=get(xs,node3(k));
    0513                         attr=node3_content.attributes;
    0514                         for m=1:length(attr)
    0515                             struct=attr{m};
    0516                             if isequal(struct.key,'value')
    0517                                 xs_element.enum{k}=struct.val; % read enumeration
    0518                             end
    0519                         end
    0520                    end
    0521                end
    0522             end
    0523         end
    0524      elseif isequal(nodename1,'xs:complexType')
    0525          for j=1:length(node2)
    0526              nodename2=get(xs,node2(j),'name');
    0527              if isequal(nodename2,'xs:attribute')
    0528                  node_content=get(xs,node2(j));
    0529                  attr=node_content.attributes;
    0530                  for k=1:length(attr)
    0531                     struct=attr{k};%read attributes
    0532                     if isequal(struct.key,'name')
    0533                         xs_element.attrib=struct.val; %read attributes of main node
    0534                     end
    0535                  end
    0536              elseif isequal(nodename2,'xs:sequence')
    0537                  xs_element.subtest=1;
    0538                  node3=children(xs,node2(j));%nodes of the sequence
    0539                  for k=1:length(node3)
    0540                      xs_subelem(k).node=node3(k);
    0541                      xs_subelem(k).testsub=0;%default
    0542                      node_content=get(xs,node3(k));
    0543                      xs_subelem(k).minOccurs=1; %default
    0544                      xs_subelem(k).maxOccurs=1; %default
    0545 %                      pref{k}=[]; %default
    0546                      if isequal(node_content.name,'xs:element')
    0547                         attr=node_content.attributes;
    0548 %                         attr{:}.key
    0549                         for l=1:length(attr)
    0550                             if isequal(attr{l}.key,'name')
    0551                                 xs_subelem(k).key=attr{l}.val;%name of the element
    0552                             elseif isequal(attr{l}.key, 'minOccurs')
    0553                                 xs_subelem(k).minOccurs=attr{l}.val;
    0554                             elseif isequal(attr{l}.key, 'maxOccurs')
    0555                                 xs_subelem(k).maxOccurs=attr{l}.val;
    0556                             end
    0557                         end
    0558                      end
    0559                      node4=children(xs,node3(k));
    0560                      for l=1:length(node4)
    0561                         res=get(xs,node4(l),'name');
    0562                         if isequal(res,'xs:complexType')%look whether the element k contains a subtree
    0563                            node5=children(xs,node4(l));
    0564                            for m=1:length(node5)
    0565                                res2=get(xs,node5(m),'name');
    0566                                if isequal(res2,'xs:sequence')
    0567                                     xs_subelem(k).testsub=1; %flag for the existence of a subtree
    0568                                end
    0569                            end
    0570                         end
    0571                      end
    0572                  end
    0573
    0574              end
    0575          end
    0576      end
    0577   end
    0578 end
    0579 % look for predefined types
    0580 if length(xs_element.type)>=3 & (xs_element.type([1:3])~='xs:')
    0581     node_type=find(xs,'/xs:schema/xs:simpleType')
    0582     for i=1:length(node_type)
    0583         content=get(xs,node_type(i));
    0584         nodeattr=content.attributes;
    0585         if ~isempty(nodeattr) & isequal(nodeattr{1}.key,'name') & isequal(nodeattr{1}.val,xs_element.type)
    0586             node1=children(xs,node_type(i));
    0587             node2=find(xs,node1,'name','xs:restriction');
    0588 %             nodename1=find(xs,
    0589             node3=children(xs,node2);
    0590             node4=find(xs,node3,'name','xs:enumeration');
    0591             for ienum=1:length(node4)
    0592                 struct2=get(xs,node4(ienum));
    0593                 enumval=struct2.attributes;
    0594                 xs_element.enum{ienum}=enumval{1}.val;
    0595             end
    0596         end
    0597      end
    0598 end
    0599
    0600 %--------------------------------------------------------
    0601 %OUTPUT:
    0602 %element.val: value of the current element, =[] in the absence of chardata value
    0603 %node: node (iud) of the element in t
    0604 %element.attr_key{iattr}: attribute key #iattr of the current element
    0605 %element.attr_val{iattr}: attribute value #iattr of the current element
    0606 %element.attrup: %structure containing the attributes of the element, including the ones unheritated from parent nodes
    0607 %subelem(iline).val : value of subelement # iline, concatenated with corresponding attributes
    0608 %subelem(iline).xsindex: index k of the subelement #iline in the list xs_subelem of the schema
    0609 %subelem(iline).index: index of the subelement #iline inside its xs_subelement, =0 when the xs_subelement is absent in t
    0610
    0611 %INPUT:
    0612 %t: xml tree
    0613 %path: path to the current element in the schema
    0614 %xs_element: current element in the schema
    0615     %xs_element.key: key label
    0616     %xs_element.type: type of data contained in the element
    0617     %xs_element.annot: annotation of nodeinput
    0618     %xs_element.attrib: list of accepted attributes keys for xs_element
    0619     %xs_element.enum: enumeration, list of accepted values
    0620     %xs_element.subtest: =1 if the element contains subelements in the schema, 0 else
    0621 %index: index of the element, =1 in case of single occurence in xs_element,=0 in case of missing element
    0622 %xs_subelem(k): subelement #k of the current element in the schema
    0623     %xs_subelem(k).node: node iud of the
    0624     %xs_subelem(k).key: key name of the subelement #k in the schema
    0625     %xs_subelem(k).testsub: =1 if element contains subelements, 0 else
    0626     %xs_subelem(k).minOccurs
    0627     %xs_subelem(k).maxOccurs
    0628
    0629 function [element,subelem]=get_xml(t,path,xs_element,node,xs_subelem)
    0630 element.attr_key='';%default
    0631 element.attr_val='';%default
    0632 element.val='';
    0633 % element.type='';
    0634 % element.testmanual=testmanual %inheritates the input manual editing flag by default
    0635 subelem=[]; %default
    0636 attrup=[];
    0637 % node=[];
    0638
    0639 % %find the element properties in the xml file
    0640 if node >= 1
    0641     elem_struct=get(t,node);
    0642     if ~xs_element.subtest
    0643         elem_contents=get(t,elem_struct.contents);
    0644         if isempty(elem_contents)
    0645             element.val=[];
    0646         else
    0647             element.val=elem_contents.value
    0648         end
    0649     end
    0650     if isfield(elem_struct,'attributes')
    0651         elem_attr=elem_struct.attributes;
    0652         for iattr=1:length(elem_attr)
    0653             element.attr_key{iattr}=elem_attr{iattr}.key ;
    0654             element.attr_val{iattr}=elem_attr{iattr}.val;
    0655 %             attrup=setfield(attrup,elem_attr{iattr}.key,elem_attr{iattr}.val);
    0656            breakdetect=find(elem_attr{iattr}.key=='/'| elem_attr{iattr}.key==':'| elem_attr{iattr}.key=='.');% find '/'
    0657            if isempty(breakdetect)
    0658 %                 comline=['attrup.' elem_attr{iattr}.key '=' elem_attr{iattr}.val ';']
    0659                 eval(['attrup.' elem_attr{iattr}.key '=''' elem_attr{iattr}.val ''';'])
    0660            end
    0661         end
    0662     end
    0663 end
    0664 %get the parent node attributes
    0665 up=1;
    0666 if node>0
    0667     nodeup=node;
    0668     while up==1;
    0669         nodeup=get(t,nodeup,'parent');%move up to the parent in the tree
    0670         if isempty(nodeup)
    0671             up=0;
    0672         else
    0673             nodeup_content=get(t,nodeup);
    0674             attrib=nodeup_content.attributes;
    0675             for iattr=1:length(attrib)
    0676                 key=attrib{iattr}.key;
    0677                 breakdetect=find(key=='/'| key==':'| key=='.');% find '/'
    0678                 if ~isfield(attrup,key) & isempty(breakdetect)
    0679                    eval(['attrup.' key '=''' attrib{iattr}.val ''';'])
    0680                 end
    0681             end
    0682         end
    0683     end
    0684     element.attrup=attrup;
    0685 end
    0686 %find the subelement properties in the xml file
    0687 if xs_element.subtest
    0688    iline=0;
    0689    for k=1:length(xs_subelem)%node2: list of subelements in the sub-sequence
    0690 %     attr=attributes(xs,'get',node2(i),1);%
    0691 %     element=attr.val;%name of the element
    0692      tag=find(t,['/' path '/' xs_element.key '/' xs_subelem(k).key]);%look for the corresponding element node in the .xml tree
    0693      struct_element=get(t,tag);%get the content of the element
    0694      if isempty(struct_element)
    0695          iline=iline+1;
    0696          subelem(iline).uid=0;
    0697          subelem(iline).xsindex=k;
    0698          subelem(iline).index=0;
    0699 %          subelem(iline).testmanual=element.testmanual;% inheritates the manual editing flag by default
    0700          if isequal(xs_subelem(k).minOccurs,'0')
    0701              subelem(iline).val='[]';%element value not mandatory in the schema
    0702          else
    0703              subelem(iline).val='[MISSING]';%element value mandatory in the schema
    0704          end
    0705 %          subelem(iline).attrup=attrup; %inheritated attributes
    0706      elseif isequal(length(struct_element),1)
    0707          contents=get(t,struct_element.contents);
    0708          iline=iline+1;
    0709          subelem(iline).uid=tag;
    0710          subelem(iline).xsindex=k;
    0711          subelem(iline).index=1;
    0712 %          subelem(iline).testmanual=element.testmanual;%
    0713          if isfield(contents,'value') & ~isempty(contents.value)
    0714              subelem(iline).val=contents.value;
    0715          elseif xs_subelem(k).testsub
    0716              subelem(iline).val='';
    0717          elseif isequal(xs_subelem(k).minOccurs,0)
    0718              subelem(iline).val='[]';%element value not mandatory in the schema
    0719          else
    0720              subelem(iline).val='[MISSING]';%element value mandatory in the schema
    0721          end
    0722 %          subelem(iline).attrup=attrup; %inheritated attributes
    0723          if isfield(struct_element,'attributes')
    0724             element_attr=struct_element.attributes;
    0725             attr_display=[];
    0726             for iattr=1:length(element_attr)
    0727 %                 attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    0728                 subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    0729 %                 subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
    0730             end
    0731          end
    0732      else%case of a multiple element
    0733          for subindex=1:length(struct_element)
    0734              contents=get(t,struct_element{subindex}.contents);
    0735              iline=iline+1;
    0736              subelem(iline).index=subindex;%index of the element
    0737              subelem(iline).xsindex=k;
    0738 %              subelem(iline).testmanual=element.testmanual;%
    0739              if isfield(contents,'value')& ~isempty(contents.value)
    0740                  subelem(iline).val=contents.value;
    0741              elseif xs_subelem(k).testsub
    0742                  subelem(iline).val='';
    0743              else
    0744                  subelem(iline).val='[]';
    0745              end
    0746 %              subelem(iline).attrup=attrup; %inheritated attributes
    0747              if isfield(struct_element{subindex},'attributes')
    0748                 element_attr=struct_element{subindex}.attributes;
    0749                 attr_display=[];
    0750                 for iattr=1:length(element_attr)
    0751 %                     attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    0752                     subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    0753 %                     subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
    0754                 end
    0755             end
    0756         end
    0757      end
    0758   end
    0759 end
    0760
    0761 %-------------------------------------
    0762 %updates the interface
    0763 function update_list(handles,path,xs_element,element,node,xs_subelem,subelem)
    0764 %-----------------------------
    0765 if xs_element.subtest% we list the sub-elements of root
    0766     set(handles.export_list,'Value',1)
    0767     set(handles.export_list,'String','')%flush the export list
    0768     set(handles.CurrentElement,'String',[path '/' xs_element.key])
    0769 %     title_element.key=[path '/' xs_element.key];
    0770 %     if ~isempty(path)
    0771 %         xsnode_index=get(handles.list_element,'UserDataIn');
    0772 %         ind=get(handles.list_element,'Value');
    0773 %         title_element.index=xsnode_index(2,ind);
    0774 %     else
    0775 %         title_element.index=1;
    0776 %     end
    0777 %     title_element.xsnode=xs_element.uid;
    0778 %     title_element.node=node;
    0779 %     set(handles.CurrentFile,'UserDataIn',title_element)%element corresponding to the title
    0780     set(handles.CurrentAnnotation,'String',xs_element.annot)
    0781     attr_col=[];
    0782     testedit=0;% cannot edit elements by default
    0783     for iattr=1:length(element.attr_key)
    0784 %          if isequal(element.attr_key{iattr},'source') & isequal(element.attr_val{iattr},'manual')
    0785 %             testedit=1;
    0786 %         end
    0787         attr_col=strvcat(attr_col,[element.attr_key{iattr} ' = ' element.attr_val{iattr}]);
    0788     end
    0789     set(handles.CurrentAttributes,'String',attr_col)
    0790     pref_col='';
    0791     key_col='';
    0792     equal_sign='';
    0793     val_col='';
    0794     for iline=1:length(subelem)
    0795         xsindex=subelem(iline).xsindex;
    0796         index(iline)=subelem(iline).index;
    0797         subuid=subelem(iline).uid;
    0798         if isempty(subuid)
    0799             list.uid(iline)=0;
    0800         else
    0801             list.uid(iline)=subuid;
    0802         end
    0803         node(iline)=xs_subelem(xsindex).node;
    0804 %         testmanual(iline)=subelem(iline).testmanual;
    0805         ikey=xs_subelem(xsindex).key;
    0806         if xs_subelem(xsindex).testsub
    0807             ival=[' + ' subelem(iline).val];
    0808         else
    0809             ival=[' = ' subelem(iline).val];
    0810         end
    0811         key_col=strvcat(key_col,ikey);
    0812         val_col=strvcat(val_col,ival);
    0813     end
    0814     list_element=[key_col val_col];
    0815     set(handles.list_element,'String',list_element)
    0816     set(handles.list_element,'Value',1)
    0817     list.xs_uid=node;
    0818     list.index=index;
    0819     set(handles.list_element,'UserData',list)
    0820     set(handles.element_attrib,'Visible','off')
    0821     set(handles.element_key,'Visible','off')
    0822     set(handles.element_value,'Visible','off')
    0823 else % we edit an element
    0824
    0825     export_list=get(handles.export_list,'String');%export list
    0826     testadd=1;
    0827     for ilist=1:length(export_list)
    0828         if isequal(xs_element.key,export_list{ilist})
    0829             testadd=0;
    0830             break
    0831         end
    0832     end
    0833     if testadd
    0834         export_list=[export_list;{xs_element.key}];
    0835         ilist=length(export_list);
    0836     end
    0837     set(handles.export_list,'String',export_list)
    0838     if iscell(element.val)
    0839         element_val=element.val{1};
    0840     else
    0841         element_val=element.val;
    0842     end
    0843     set(handles.element_value,'String',element_val)
    0844     export_val=get(handles.export_list,'UserData');
    0845     export_val{ilist}=element_val;
    0846     set(handles.export_list,'UserData',export_val);
    0847     set(handles.element_annot,'String',xs_element.annot)
    0848     set(handles.element_type,'String',['type:  ' xs_element.type])
    0849     attr_col=[];
    0850     testedit=0;% cannot edit element by default
    0851     for iattr=1:length(element.attr_key)
    0852 %         if isequal(element.attr_key{iattr},'source') & isequal(element.attr_val{iattr},'manual')
    0853 %             testedit=1;
    0854 %         end
    0855         attr_col=strvcat(attr_col,[element.attr_key{iattr} ' = ' element.attr_val{iattr}]);
    0856     end
    0857     set(handles.element_attrib,'String',attr_col)
    0858     set(handles.element_key,'String',xs_element.key)
    0859
    0860
    0861     if isempty(xs_element.enum)
    0862         set(handles.element_value,'Value',1)
    0863         set(handles.element_value,'Style','edit')
    0864     else % case of an enumeration of possible values
    0865          list_enum=[];
    0866          list_val=[];
    0867          for ienum=1:length(xs_element.enum)
    0868              list_enum{ienum,1}=xs_element.enum{ienum};
    0869              if isequal(xs_element.enum{ienum},element_val)
    0870                  list_val=ienum;
    0871              end
    0872          end
    0873          if isempty(list_val)
    0874              list_enum{length(xs_element.enum)+1,1}=['[' element_val ']'];%show the non-valid element between brackets
    0875              list_val=length(xs_element.enum)+1;
    0876          end
    0877          set(handles.element_value,'Style','popupmenu')
    0878          set(handles.element_value,'String',list_enum)
    0879          set(handles.element_value,'Value',list_val)
    0880      end
    0881      if isempty(element.val)
    0882          testedit=1;%allow element editing if value is missing
    0883      end
    0884      set(handles.element_attrib,'Visible','On')
    0885      set(handles.element_key,'Visible','On')
    0886      set(handles.element_value,'Visible','On')
    0887 end
    0888 set(handles.element_value,'UserData',node)
    0889 if ~testedit && isfield(element,'attrup') & isfield(element.attrup,'source')&& ~isequal(element.attrup.source,'manual')
    0890      set(handles.element_value,'Enable','inactive')
    0891 else
    0892     set(handles.element_value,'Enable','on')
    0893 end
    0894
    0895
    0896 % --- Executes on button press in SAVE.
    0897 function SAVE_Callback(hObject, eventdata, handles)
    0898 global t
    0899 DataIn=get(get(handles.SAVE,'parent'),'UserData');
    0900 CurrentFile=get(handles.CurrentFile,'String');
    0901 if isfield(DataIn,'Schema')
    0902 if ~isempty(DataIn.Schema)% update ref to schema
    0903     attrxsd=attributes(t,'get',1);
    0904     setest=0;
    0905     for iattr=1:length(attrxsd)
    0906         if isequal(attrxsd{iattr}.key,'xsi:noNamespaceSchemaLocation')
    0907             t= attributes(t,'set',1,iattr,'xsi:noNamespaceSchemaLocation',DataIn.Schema);
    0908             setest=1;
    0909         end
    0910     end
    0911     if setest==0;
    0912         t=attributes(t,'add',1,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
    0913         t= attributes(t,'add',1,'xsi:noNamespaceSchemaLocation',DataIn.Schema);
    0914     end
    0915 end
    0916 end
    0917 copyfile(CurrentFile,[CurrentFile '.bak']);
    0918 save(t,CurrentFile);
    0919
    0920 %-------------------------------------
    0921 % creates and/or set values to an element in t
    0922 %t: xml tree
    0923 %RootUid: uid of t under which we introduce an element
    0924 %node: uid of the element that we correct, if =0, a new element is created
    0925 %key: key name of the element
    0926 %value: new value of the element
    0927 function t=set_element(t,RootUid,node,key,value)
    0928 %create the subelement if needed
    0929 if isequal(node,0)
    0930    [t,node]= add(t,RootUid,'element',key);
    0931 end
    0932 node_chardata=children(t,node); %corresponding data node
    0933 if isempty(node_chardata)%if the data does not exist in t, create it
    0934     t=add(t,node,'chardata',value);
    0935 elseif isequal(length(node_chardata),1)&isequal(get(t,node_chardata,'type'),'chardata')% update only a simple element with 'chardata'
    0936     t=set(t,node_chardata,'value',value);%modify existing data
    0937 end
    0938 attr=attributes(t,'get',node);
    0939 if isempty(attr)
    0940     t=attributes(t,'add',node,'source','manual');%indicate a manual eidting
    0941 end
    0942
    0943 % --- Executes on selection change in element_attr_val.
    0944 function element_attr_val_Callback(hObject, eventdata, handles)
    0945 % hObject    handle to element_attr_val (see GCBO)
    0946 % eventdata  reserved - to be defined in a future version of MATLAB
    0947 % handles    structure with handles and user data (see GUIDATA)
    0948
    0949 % Hints: contents = get(hObject,'String') returns element_attr_val contents as cell array
    0950 %        contents{get(hObject,'Value')} returns selected item from element_attr_val
    0951
    0952
    0953 % --- Executes on button press in ADD.
    0954 function ADD_Callback(hObject, eventdata, handles)
    0955 % hObject    handle to ADD (see GCBO)
    0956 % eventdata  reserved - to be defined in a future version of MATLAB
    0957 % handles    structure with handles and user data (see GUIDATA)
    0958
    0959 %----------------------------------------
    0960 %read an xml file without schema
    0961 function [Data,testsimple]=displ_xml(handles,t,root_uid,DataIn,heditxml)
    0962 Data=DataIn;%default
    0963 if ~isfield(Data,'CurrentUid')
    0964     Data.CurrentUid=[];
    0965 end
    0966 CurrentFile=get(handles.CurrentFile,'String');
    0967
    0968 %display the current element
    0969 root_element=get(t,root_uid);
    0970 uidparent=root_uid;
    0971 if isfield(root_element,'name')
    0972     CurrentElement=root_element.name;
    0973     while ~isequal(uidparent,1)%while the first level has not been reached
    0974         uidparent=parent(t,uidparent);
    0975         dirdat=get(t,uidparent);
    0976         if isfield(dirdat,'name')
    0977             CurrentElement=[dirdat.name '/' CurrentElement];
    0978         end
    0979     end
    0980     set(handles.CurrentElement,'String',CurrentElement)
    0981 end
    0982 list_uid=children(t,root_uid);
    0983 %case of a single element
    0984 testsimple=0;
    0985 filedat=[];
    0986 if ~isempty(list_uid)
    0987     filedat=get(t,list_uid(1))
    0988     if isfield(filedat,'type') & isequal(filedat.type,'chardata') &isfield(filedat,'value')
    0989         testsimple=1;%simple element
    0990     end
    0991 end
    0992
    0993 %attributes of the current element
    0994 nbattrib= attributes(t,'length',root_uid);
    0995 testopen=0;
    0996 attr_col=[];
    0997 for iattr=1:nbattrib
    0998     attr= attributes(t,'get',root_uid,iattr);
    0999     if isequal(attr.key,'source')% look for 'source' attribute
    1000         if isequal(attr.val,'file')%if the source is 'file', look for the path and open it
    1001            if isfield(filedat,'type') & isequal(filedat.type,'chardata') &isfield(filedat,'value')
    1002                cur_file=filedat.value;
    1003                uidparent=root_uid;%initialization
    1004                while ~isequal(uidparent,1)%while the first level has not been reached
    1005                     uidparent=parent(t,uidparent);
    1006                     dirdat=get(t,uidparent);
    1007                     if isfield(dirdat,'type') & isequal(dirdat.type,'element') & isfield(dirdat,'name')
    1008                         nbattrib_up= attributes(t,'length',uidparent);
    1009                         for iattr_up=1:nbattrib_up
    1010                             attr= attributes(t,'get',uidparent,iattr_up);
    1011 %                             if isequal(attr.key,'source')&isequal(attr.val,'directory')% look for 'source' attribute
    1012                               if isequal(attr.key,'DirName')
    1013                                  cur_file=fullfile(attr.val,cur_file);
    1014                              end
    1015                         end
    1016                     end
    1017                end
    1018                RootPath=fileparts(CurrentFile);%path to the current .xml file
    1019                cur_file=fullfile(RootPath,cur_file)
    1020                set(handles.CurrentAttributes,'UserData',cur_file)%will be searched by uvmat
    1021                [path,fil,ext]=fileparts(cur_file);
    1022                if ~exist(cur_file,'file')
    1023                    warndlg_uvmat(['non-existent link file' cur_file],'ERROR') % A FAIRE: propose to updtate the .xml file
    1024                    return
    1025                elseif isequal(ext,'.xml')
    1026                    if ~isfield(Data,'UpFile')
    1027                        Data.UpFile={CurrentFile};
    1028                    else
    1029                        Data.UpFile=[{CurrentFile};Data.UpFile];
    1030                    end
    1031                    set(heditxml,'UserData',Data)
    1032                    set(handles.CurrentFile,'String',cur_file)
    1033                    CurrentFile_Callback(handles.CurrentFile, [], handles)
    1034                else
    1035                    if isequal(get(heditxml,'Tag'),'browser'); %if editxml has been called as a browser
    1036                        set(heditxml,'Tag','idle')% signal for uvmat browser
    1037                    else
    1038                        uvmat({cur_file}); %open the link fiel with uvmat
    1039                    end
    1040                    return
    1041                end
    1042            end
    1043        %elseif isequal(attr.val,'dir') A FAIRE : check directory
    1044        %else A FAIRE: edit the element
    1045         end
    1046     end
    1047     attr_col=strvcat(attr_col,[attr.key ' = ' attr.val]);
    1048 end
    1049 set(handles.CurrentAttributes,'String',attr_col)
    1050
    1051 %list subtree
    1052 if ~testsimple
    1053     list_element=[];
    1054 %      Data.CurrentUid=[Data.CurrentUid root_uid]%record new current uid
    1055     for iline=1:length(list_uid)
    1056         element=get(t,list_uid(iline));
    1057         if isfield(element,'type')&isequal(element.type,'element')
    1058              list_element{iline,2}=element.name;
    1059              child_uid=children(t,list_uid(iline));
    1060              subelem=get(t,child_uid);
    1061              if isfield(subelem,'type')& isfield(subelem,'value') & isequal(subelem.type,'chardata')
    1062                 data_read=subelem.value;
    1063                 list_element{iline,3}=['= ' data_read];
    1064             end
    1065             if iscell(subelem)|(isfield(subelem,'type')&isequal(subelem.type,'element'))
    1066                 list_element{iline,1}='+ ';%sign for subtree existence
    1067             else
    1068                 list_element{iline,1}='  ';
    1069             end
    1070             nbattr=attributes(t,'length',list_uid(iline));
    1071             if nbattr==1
    1072                 attr=attributes(t,'get',list_uid(iline));
    1073                 list_element{iline,4}=[attr.key '='];
    1074                 list_element{iline,5}=attr.val;
    1075             elseif nbattr>1
    1076                 for iattr=1:nbattr
    1077                     attr=attributes(t,'get',list_uid(iline),iattr);
    1078                     list_element{iline,2+2*iattr}=[attr.key '='];
    1079                     list_element{iline,3+2*iattr}=attr.val;
    1080                 end
    1081             end
    1082         end
    1083     end
    1084     set(handles.list_element,'Value',1)%select the first line of list_element by default
    1085     set(handles.list_element,'String',cell2tab(list_element,' ') )
    1086     list.uid=list_uid;
    1087     set(handles.list_element,'UserData',list)
    1088 end
    1089 %---------------------------------------------------------
    1090 %-------------------------------------
    1091 %updates the interface
    1092 function update_ref_list(hh,xs_element,element,node,xs_subelem,subelem)
    1093 %-----------------------------
    1094 pref_col='';
    1095 key_col='';
    1096 equal_sign='';
    1097 val_col='';
    1098 for iline=1:length(subelem)
    1099     xsindex=subelem(iline).xsindex;
    1100     indexcur=subelem(iline).index;
    1101     subuid=subelem(iline).uid;
    1102         if isempty(subuid)
    1103              RefDataIn.uid(iline)=0;
    1104         else
    1105              RefDataIn.uid(iline)=subuid;
    1106         end
    1107     index(iline)=indexcur;
    1108     node(iline)=xs_subelem(xsindex).node;
    1109 %         testmanual(iline)=subelem(iline).testmanual;
    1110     ikey=xs_subelem(xsindex).key;
    1111     if xs_subelem(xsindex).testsub
    1112         ival=[' + ' subelem(iline).val];
    1113     else
    1114         ival=[' = ' subelem(iline).val];
    1115     end
    1116     key_col=strvcat(key_col,ikey);
    1117     val_col=strvcat(val_col,ival);
    1118 end
    1119 RefDataIn.xs_uid=node;
    1120 list_element=[key_col val_col];
    1121 siztext=size(list_element);
    1122 set(hh,'Value',[1:siztext(1)])
    1123 set(hh,'String',list_element)
    1124 set(hh,'UserData',RefDataIn)
    1125
    1126 %
    1127 % function RefFile_Callback(hObject, eventdata, handles)
    1128 % global t_ref xs
    1129 % t_ref=xmltree(get(hObject,'String'));%open the xml file fileinput
    1130 % heditxml=get(hObject,'parent');
    1131 % DataIn=get(get(hObject,'parent'),'UserData');
    1132 % % set(heditxml,'Units','pixel')
    1133 % figpos=get(heditxml,'Position')
    1134 % % title_element=get(handles.element_cur,'UserDataIn');
    1135 % % xs_node=xsnode_index(1,ind);
    1136 % % index_chosen=xsnode_index(2,ind);
    1137 % if isfield(DataIn,'fig_ref')&ishandle(DataIn.fig_ref)
    1138 %     figure(DataIn.fig_ref);
    1139 % else
    1140 %     DataIn.fig_ref=figure;
    1141 % end
    1142 % set(DataIn.fig_ref,'Name',get(hObject,'String'))
    1143 % set(DataIn.fig_ref,'MenuBar','none')
    1144 % newfigpos=[figpos(1)+figpos(3) figpos(2)+0.4*figpos(4) 0.5*figpos(3) 0.3*figpos(4)];
    1145 % set(DataIn.fig_ref,'Units','normalized')
    1146 % set(DataIn.fig_ref,'Position',newfigpos)
    1147 % DataIn.h_ref=uicontrol('Style','listbox', 'Max',2,'Units','pixel','Position', [0 0 newfigpos(3) newfigpos(4)], ...
    1148 %         'FontName','FixedWidth','Tag','listbox');
    1149 % if isfield(DataIn,'xs_CurrentUid');
    1150 %     xs_CurrentUid=DataIn.xs_CurrentUid(end);
    1151 % else
    1152 %     DataIn.xs_CurrentUid=find(xs,'/xs:schema/xs:element');%uid of the root element in the schema
    1153 % end
    1154 % [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_CurrentUid(end));
    1155 % xs_element.key
    1156 % tag0=find(t_ref,['/' path '/' xs_element.key]);
    1157 % if length(tag0)>=1
    1158 %     CurrentRefNode=tag0(1);%chose the first occurence of the element
    1159 % else
    1160 %     CurrentRefNode=0;
    1161 % end
    1162 % [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,CurrentRefNode,xs_subelem);
    1163 % update_ref_list(DataIn.h_ref,xs_element,ref_element,CurrentRefNode,xs_subelem,ref_subelem);
    1164 % siztext=size(get(DataIn.h_ref,'String'));
    1165 % set(DataIn.h_ref,'Value',[1:siztext(1)]); %select the whole list by default
    1166 % set(heditxml,'UserData',DataIn)
    1167 % set(handles.ref_data,'Value',siztext(1)); %select the whole list by default
    1168 % 'TESTimport'
    1169 % title_element=get(handles.element_cur,'UserDataIn')
    1170 % xs_node=title_element.xsnode;%uid of the element in the schema
    1171 % node=title_element.node;
    1172 % t=flush(t,node);%removes the corresponding subtree in t
    1173 % [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node);%scan the schema
    1174 % tag0=find(t_import,['/' path '/' xs_element.key])
    1175 % if isempty(tag)
    1176 %     errordlg(['element /' path '/' xs_element.key ' not found in' fileinput])
    1177 %     return
    1178 % end
    1179 % % [element_import,node_import]=get_xml(t_import,path,xs_element,1,xs_subelem);% read the corresponding xml data
    1180 % node2_import=children(t_import,tag0);
    1181 % % t_import=branch(t_import,node_import);% extract branch of the new file
    1182 % % %removes the corresponding subtree in t
    1183 % for inode=1:length(node2_import)
    1184 %     struct=get(t_import,node2_import(inode))
    1185 %     if isfield(struct,'type') & isfield(struct,'name')%if the node is an elmeent type
    1186 %         node3_import=children(t_import,node2_import(inode))
    1187 %        [t,newuid]=add(t,node,struct.type,struct.name);
    1188 %        for inode2=1:length(node3_import)
    1189 %            struct2=get(t_import,node3_import(inode2))
    1190 %            if isequal(struct2.type,'chardata')
    1191 %                 t=add(t,newuid,'chardata',struct2.value);
    1192 %             end
    1193 %         end
    1194 %     end
    1195 % end
    1196 % --- Executes on button press in replicate.
    1197 function replicate_Callback(hObject, eventdata, handles)
    1198 global xs  t
    1199
    1200 export_list=get(handles.export_list,'String');
    1201 export_val=get(handles.export_list,'UserData');
    1202 heditxml=get(handles.replicate,'parent');
    1203 Data=get(heditxml,'UserData')
    1204
    1205 hdataview=findobj(allchild(0),'Name','dataview')
    1206 if isempty(hdataview)
    1207     hdataview=dataview;
    1208     return
    1209 end
    1210 hhdataview=guidata(hdataview);
    1211 CurrentPath=get(hhdataview.CurrentFile,'String');
    1212 ListExperiments=get(hhdataview.ListExperiments,'String');
    1213 Value=get(hhdataview.ListExperiments,'Value');
    1214 if ~isequal(Value,1)
    1215     ListExperiments=ListExperiments(Value);
    1216 end
    1217 ListDevices=get(hhdataview.ListDevices,'String');
    1218 Value=get(hhdataview.ListDevices,'Value');
    1219 if ~isequal(Value,1)
    1220     ListDevices=ListDevices(Value);
    1221 end
    1222 ListRecords=get(hhdataview.ListRecords,'String');
    1223 Value=get(hhdataview.ListRecords,'Value');
    1224 if ~isequal(Value,1)
    1225     ListRecords=ListRecords(Value);
    1226 end
    1227 % uvmat('runplus_Callback',hObject,eventdata,handleshaxes)
    1228 [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
    1229 ListXml=get(hhdataview.ListXml,'String');
    1230 Value=get(hhdataview.ListXml,'Value');
    1231 if isequal(Value,1)
    1232     warndlg_uvmat('you need to select the xml files to edit','ERROR')
    1233     return
    1234 end
    1235 ListXml=ListXml(Value);%list of
    1236 for iexp=1:length(List.Experiment)
    1237     ExpName=List.Experiment{iexp}.name;
    1238     if isfield(List.Experiment{iexp},'Device')
    1239         for idevice=1:length(List.Experiment{iexp}.Device)
    1240             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
    1241             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    1242                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
    1243                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
    1244                     for ilistxml=1:length(ListXml)
    1245                         if isequal(FileName,ListXml{ilistxml})
    1246                             xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
    1247                             t_export=xmltree(xmlfullname);
    1248                             rootelement=get(t_export,1,'name');
    1249                             uidlist=Data.CurrentUid;
    1250                             if isequal(rootelement,get(t,1,'name'))
    1251                                 backupfile=xmlfullname;
    1252                                 testexist=2;
    1253                                 while testexist==2
    1254                                    backupfile=[backupfile '~'];
    1255                                    testexist=exist(backupfile,'file');
    1256                                 end
    1257                                 [success,message]=copyfile(xmlfullname,backupfile);%make backup
    1258                                 if ~isequal(success,1)
    1259                                     warndlg_uvmat(['Error in the backup of ' xmlfullname],'ERROR')
    1260                                     return
    1261                                 end
    1262                                 findstr=['/' rootelement];
    1263                                 uid_export(1)=1;
    1264                                 % fill the root elements if absent
    1265                                 for index=2:length(uidlist)
    1266                                     name_t=get(t,uidlist(index),'name')
    1267                                     findstr=[findstr '/' name_t]
    1268                                     uid=find(t_export,findstr)
    1269                                     if isempty(uid)
    1270                                         [t_export,uid_export(index)]=add(t_export,uid_export(index-1),'element',name_t);
    1271                                     else
    1272                                         uid_export(index)=uid;
    1273                                     end
    1274                                 end
    1275                                 % chardata......
    1276                             end
    1277                             break
    1278                         end
    1279                     end
    1280 %                     [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
    1281 %                     if test
    1282 %                         [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
    1283 %                     end
    1284                 end
    1285              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    1286                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    1287                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
    1288                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
    1289                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
    1290                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
    1291                             for ilistxml=1:length(ListXml)
    1292                                 if isequal(FileName,ListXml{ilistxml})
    1293                                     xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName)
    1294                                     break
    1295                                 end
    1296                             end
    1297 %                             [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
    1298 %                             if test
    1299 %                                 [FileName ' , Heading updated']
    1300 %                             end
    1301                         end
    1302                     end
    1303                 end
    1304             end
    1305         end
    1306     end
    1307 end
    1308 return
    1309 %%%%%%%%%%% A REVOIR
    1310 % Copier la liste des elements selectionnés dans dataview
    1311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1312 %ANCIEN:
    1313 heditxml=get(hObject,'parent');
    1314 DataIn=get(heditxml,'UserData');
    1315 if ~isfield(DataIn,'h_ref')
    1316     DataIn.h_ref=[];
    1317 end
    1318 if ~ishandle(DataIn.h_ref)
    1319     errordlg('no source file opened for import')
    1320     return
    1321 end
    1322 %create the current root element if needed
    1323 LengthElement=length(DataIn.CurrentUid);
    1324 FilledUid=find(DataIn.CurrentUid~=0);
    1325 LengthFilled=FilledUid(end);
    1326 for irank=LengthFilled+1:LengthElement
    1327     attrib=attributes(xs,'get',DataIn.xs_CurrentUid(irank),1);
    1328     [t,DataIn.CurrentUid(irank)]=add(t,DataIn.CurrentUid(irank-1),'element',attrib.val);
    1329 end
    1330
    1331 %copy list of subelements
    1332 RefDataIn=get(DataIn.h_ref,'UserData');
    1333 list=get(handles.list_element,'UserData');%=,[node;index]
    1334 for ilist=get(DataIn.h_ref,'Value')
    1335     node_content=get(xs,RefDataIn.xs_uid(ilist));
    1336     if ~isempty(node_content) & isfield(node_content,'attributes')
    1337         attrib=node_content.attributes;
    1338         for iattr=1:length(attrib)
    1339             struct=attrib{iattr};
    1340             if isequal(struct.key,'name')
    1341                 key=struct.val; % read element key name
    1342             end
    1343         end
    1344     end
    1345     value='';
    1346     if ~isequal(RefDataIn.uid(ilist),0)
    1347         child_uid=children(t_ref,RefDataIn.uid(ilist));
    1348         if isequal(length(child_uid),1)
    1349             content=get(t_ref,child_uid);
    1350             if isfield(content,'type') &isfield(content,'value')& isequal(content.type,'chardata')
    1351                 value=content.value;
    1352             end
    1353         end
    1354     end
    1355     t=set_element(t,DataIn.CurrentUid(end),list.uid(ilist),key,value);
    1356 end
    1357 set(heditxml,'UserData',DataIn)
    1358 %update the current listing
    1359 [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid(end));
    1360 [element,subelem]=get_xml(t,path,xs_element,DataIn.CurrentUid(end),xs_subelem);
    1361 update_list(handles,path,xs_element,element,DataIn.CurrentUid(end),xs_subelem,subelem);
    1362 % t=set_xml(t,xs_DataIn,subelem)
    1363 %edit list of subelments:
    1364
    1365 %A REVOIR
    1366 % xsnode_index=get(handles.list_element,'UserDataIn')
    1367 % xs_node=xsnode_index(1,ind);
    1368 % RefDataIn=get(handles.ref_data,'UserDataIn');
    1369 % subelem=RefDataIn.subelem;
    1370 % xsnode_index=get(handles.list_element,'UserDataIn');%data on the xs_nodes of the subelements
    1371 % ref_list=get(handles.ref_data,'Value');%selected indices in the list of reference subelements
    1372 % xs_node=xsnode_index(1,ref_list);%xs_nodes of the selected subelements
    1373 % % index_chosen=xsnode_index(2,ref_list);% indices in the list of occurence for a subelement
    1374 % % for ilist=ref_list
    1375 % ilist=1;
    1376 % while icontinue
    1377 %     'TESTCOPY'
    1378 %     [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node(ilist))
    1379 %     xs_subelem.key
    1380 %     tsub=subelem(ilist).tsub
    1381 %     xsnode_index(2,ilist)
    1382 %     [ref_elem,ref_node,ref_subelem]=get_xml(tsub,'',xs_element,1,xs_subelem)
    1383 %     ref_subelem.val
    1384 %     testedit= ~isfield(element.attrup,'source') | isequal(element.attrup.source,'manual') %| element vide
    1385 %
    1386 %
    1387 %     icontinue=0
    1388 % end
    1389 % function [element,node,subelem]=get_xml(t,path,xs_element,node,xs_subelem)
    1390 % element.attr_key='';%default
    1391 % element.attr_val='';%default
    1392 % element.val='';
    1393 % % element.type='';
    1394 % % element.testmanual=testmanual %inheritates the input manual editing flag by default
    1395 % subelem=[]; %default
    1396 % attrup=[];
    1397 % % node=[];
    1398 %
    1399 % % %find the element properties in the xml file
    1400 % if node >= 1
    1401 %     elem_struct=get(t,node);
    1402 %     if ~xs_element.subtest
    1403 %         elem_contents=get(t,elem_struct.contents);
    1404 %         if isempty(elem_contents)
    1405 %             element.val=[];
    1406 %         else
    1407 %             element.val=elem_contents.value
    1408 %         end
    1409 %     end
    1410 %     if isfield(elem_struct,'attributes')
    1411 %         elem_attr=elem_struct.attributes;
    1412 %         for iattr=1:length(elem_attr)
    1413 %             element.attr_key{iattr}=elem_attr{iattr}.key ;
    1414 %             element.attr_val{iattr}=elem_attr{iattr}.val;
    1415 % %             attrup=setfield(attrup,elem_attr{iattr}.key,elem_attr{iattr}.val);
    1416 %            breakdetect=find(elem_attr{iattr}.key=='/'| elem_attr{iattr}.key==':'| elem_attr{iattr}.key=='.');% find '/'
    1417 %            if isempty(breakdetect)
    1418 % %                 comline=['attrup.' elem_attr{iattr}.key '=' elem_attr{iattr}.val ';']
    1419 %                 eval(['attrup.' elem_attr{iattr}.key '=''' elem_attr{iattr}.val ''';'])
    1420 %            end
    1421 %         end
    1422 %     end
    1423 % end
    1424 % %get the parent node attributes
    1425 % up=1
    1426 % if node>0
    1427 %     nodeup=node;
    1428 %     while up==1;
    1429 %         nodeup=get(t,nodeup,'parent');%move up to the parent in the tree
    1430 %         if isempty(nodeup)
    1431 %             up=0;
    1432 %         else
    1433 %             nodeup_content=get(t,nodeup);
    1434 %             attrib=nodeup_content.attributes;
    1435 %             for iattr=1:length(attrib)
    1436 %                 key=attrib{iattr}.key;
    1437 %                 breakdetect=find(key=='/'| key==':'| key=='.');% find '/'
    1438 %                 if ~isfield(attrup,key) & isempty(breakdetect)
    1439 %                    eval(['attrup.' key '=''' attrib{iattr}.val ''';'])
    1440 %                 end
    1441 %             end
    1442 %         end
    1443 %     end
    1444 %     element.attrup=attrup;
    1445 % end
    1446 % %find the subelement properties in the xml file
    1447 % if xs_element.subtest
    1448 %    iline=0;
    1449 %    for k=1:length(xs_subelem)%node2: list of subelements in the sub-sequence
    1450 % %     attr=attributes(xs,'get',node2(i),1);%
    1451 % %     element=attr.val;%name of the element
    1452 %      tag=find(t,['/' path '/' xs_element.key '/' xs_subelem(k).key]);%look for the corresponding element node in the .xml tree
    1453 %      struct_element=get(t,tag);%get the content of the element
    1454 %      if isempty(struct_element)
    1455 %          iline=iline+1;
    1456 %          subelem(iline).xsindex=k;
    1457 %          subelem(iline).index=0;
    1458 % %          subelem(iline).testmanual=element.testmanual;% inheritates the manual editing flag by default
    1459 %          if isequal(xs_subelem(k).minOccurs,0)
    1460 %              subelem(iline).val='[]';%element value not mandatory in the schema
    1461 %          else
    1462 %              subelem(iline).val='[MISSING]';%element value mandatory in the schema
    1463 %          end
    1464 % %          subelem(iline).attrup=attrup; %inheritated attributes
    1465 %      elseif isequal(length(struct_element),1)
    1466 %          contents=get(t,struct_element.contents);
    1467 %          iline=iline+1;
    1468 %          subelem(iline).xsindex=k;
    1469 %          subelem(iline).index=1;
    1470 % %          subelem(iline).testmanual=element.testmanual;%
    1471 %          if isfield(contents,'value') & ~isempty(contents.value)
    1472 %              subelem(iline).val=contents.value;
    1473 %          elseif xs_subelem(k).testsub
    1474 %              subelem(iline).val='';
    1475 %          elseif isequal(xs_subelem(k).minOccurs,0)
    1476 %              subelem(iline).val='[]';%element value not mandatory in the schema
    1477 %          else
    1478 %              subelem(iline).val='[MISSING]';%element value mandatory in the schema
    1479 %          end
    1480 % %          subelem(iline).attrup=attrup; %inheritated attributes
    1481 %          if isfield(struct_element,'attributes')
    1482 %             element_attr=struct_element.attributes;
    1483 %             attr_display=[];
    1484 %             for iattr=1:length(element_attr)
    1485 % %                 attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    1486 %                 subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    1487 % %                 subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
    1488 %             end
    1489 %          end
    1490 %      else%case of a multiple element
    1491 %          for subindex=1:length(struct_element)
    1492 %              contents=get(t,struct_element{subindex}.contents);
    1493 %              iline=iline+1;
    1494 %              subelem(iline).index=subindex;%index of the element
    1495 %              subelem(iline).xsindex=k;
    1496 % %              subelem(iline).testmanual=element.testmanual;%
    1497 %              if isfield(contents,'value')& ~isempty(contents.value)
    1498 %                  subelem(iline).val=contents.value;
    1499 %              elseif xs_subelem(k).testsub
    1500 %                  subelem(iline).val='';
    1501 %              else
    1502 %                  subelem(iline).val='[]';
    1503 %              end
    1504 % %              subelem(iline).attrup=attrup; %inheritated attributes
    1505 %              if isfield(struct_element{subindex},'attributes')
    1506 %                 element_attr=struct_element{subindex}.attributes;
    1507 %                 attr_display=[];
    1508 %                 for iattr=1:length(element_attr)
    1509 % %                     attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    1510 %                     subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key '  =  ' element_attr{iattr}.val];
    1511 % %                     subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val);
    1512 %                 end
    1513 %             end
    1514 %         end
    1515 %      end
    1516 %   end
    1517 % end
    1518
    1519
    1520 % --- Executes on button press in HELP.
    1521 function HELP_Callback(hObject, eventdata, handles)
    1522 path_to_uvmat=which ('uvmat')% check the path of uvmat
    1523 pathelp=fileparts(path_to_uvmat);
    1524 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
    1525 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
    1526 else
    1527 web([helpfile '#editxml'])
    1528 end
    1529
    1530
    1531 % --- Executes on button press in Export.
    1532 function Export_Callback(hObject, eventdata, handles)
    1533 val=get(handles.Export,'Value');
    1534 if val
    1535     set(handles.Export,'BackgroundColor',[0 1 0])
    1536     set(handles.export_list,'Visible','on')
    1537     set(handles.replicate,'Visible','on')
    1538     h_dataview=findobj(allchild(0),'name',dataview');
    1539     if isempty(h_dataview)
    1540        % CurrentFile=get(handles.CurrentFile,'String');
    1541         dataview;
    1542     end
    1543 else
    1544      set(handles.Export,'BackgroundColor',[0.7 0.7 0.7])
    1545     set(handles.export_list,'Visible','off')
    1546     set(handles.replicate,'Visible','off')
    1547 end
    1548
    1549
    1550 % --- Executes on button press in pushbutton9.
    1551 function pushbutton9_Callback(hObject, eventdata, handles)
    1552 % hObject    handle to pushbutton9 (see GCBO)
    1553 % eventdata  reserved - to be defined in a future version of MATLAB
    1554 % handles    structure with handles and user data (see GUIDATA)
    1555
    1556