[2] | 1 | %'editxml': function for editing xml files using a xml schema (associated with the GUI editxml.fig) |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function heditxml=editxml(inputfile) |
---|
| 4 | % |
---|
| 5 | %OUTPUT: heditxml: graphic handle of the GUI |
---|
| 6 | % |
---|
| 7 | %INPUT: inputfile: name of an xml file |
---|
[89] | 8 | |
---|
[2] | 9 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 10 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
| 11 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 12 | % This file is part of the toolbox UVMAT. |
---|
| 13 | % |
---|
| 14 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 15 | % it under the terms of the GNU General Public License as published by |
---|
| 16 | % the Free Software Foundation; either version 2 of the License, or |
---|
| 17 | % (at your option) any later version. |
---|
| 18 | % |
---|
| 19 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 20 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 21 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 22 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
| 23 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 24 | |
---|
| 25 | function varargout = editxml(varargin) |
---|
| 26 | |
---|
| 27 | % Begin initialization code - DO NOT EDIT |
---|
| 28 | gui_Singleton = 1; |
---|
| 29 | gui_State = struct('gui_Name', mfilename, ... |
---|
| 30 | 'gui_Singleton', gui_Singleton, ... |
---|
| 31 | 'gui_OpeningFcn', @editxml_OpeningFcn, ... |
---|
| 32 | 'gui_OutputFcn', @editxml_OutputFcn, ... |
---|
| 33 | 'gui_LayoutFcn', [] , ... |
---|
| 34 | 'gui_Callback', []); |
---|
[153] | 35 | if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
[2] | 36 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | if nargout |
---|
| 40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
| 41 | else |
---|
| 42 | gui_mainfcn(gui_State, varargin{:}); |
---|
| 43 | end |
---|
| 44 | % End initialization code - DO NOT EDIT |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | % --- Executes just before editxml is made visible. |
---|
| 48 | function editxml_OpeningFcn(hObject, eventdata, handles, varargin) |
---|
| 49 | % This function has no output args, see OutputFcn. |
---|
| 50 | % hObject handle to figure |
---|
| 51 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 52 | % handles structure with handles and user data (see GUIDATA) |
---|
| 53 | % varargin command line arguments to editxml (see VARARGIN) |
---|
| 54 | |
---|
| 55 | % set(handles.replicate,'String',['copy';'<---']) |
---|
| 56 | if nargin |
---|
| 57 | CurrentFile=varargin{1} |
---|
| 58 | else |
---|
| 59 | CurrentFile=[]; |
---|
| 60 | end |
---|
| 61 | % if exist('varargin') & length(varargin)>=1 |
---|
| 62 | % CurrentFile=cell2mat(varargin{1}); |
---|
| 63 | % else |
---|
| 64 | % CurrentFile=[]; |
---|
| 65 | % end |
---|
| 66 | % Choose default command line output for editxml |
---|
| 67 | handles.output = hObject; |
---|
| 68 | % set(hObject,'Units','pixel') |
---|
| 69 | if exist(CurrentFile,'file') |
---|
| 70 | [PathName,Nme,FileExt]=fileparts(CurrentFile); |
---|
| 71 | if isequal(FileExt,'.xls') |
---|
| 72 | DataIn.hfig_xls=read_xls(CurrentFile);% DataIn.hfig_xls=handle of the Excel display figure |
---|
| 73 | DataIn.CurrentUid=1; |
---|
| 74 | figpos=get(hObject,'Position');%position of the editxml interface |
---|
| 75 | figposunit=get(hObject,'Units');%unity used to indicate position |
---|
| 76 | newfigpos=[figpos(1)-0.5*figpos(3) figpos(2) figpos(3) figpos(4)]; |
---|
| 77 | set(DataIn.hfig_xls,'Units',figposunit) |
---|
| 78 | set(DataIn.hfig_xls,'Position',newfigpos); %set position of the Excel display figure |
---|
| 79 | set(hObject,'UserData',DataIn) |
---|
| 80 | else |
---|
| 81 | set(handles.CurrentFile,'String',CurrentFile) |
---|
| 82 | CurrentFile_Callback(hObject, eventdata, handles) |
---|
| 83 | end |
---|
| 84 | end |
---|
| 85 | % Update handles structure |
---|
| 86 | guidata(hObject, handles); |
---|
| 87 | |
---|
| 88 | %---------------------------------------------------------------- |
---|
| 89 | % --- Outputs from this function are returned to the command line. |
---|
| 90 | function varargout = editxml_OutputFcn(hObject, eventdata, handles) |
---|
| 91 | % varargout cell array for returning output args (see VARARGOUT); |
---|
| 92 | % hObject handle to figure |
---|
| 93 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 94 | % handles structure with handles and user data (see GUIDATA) |
---|
| 95 | |
---|
| 96 | % Get default command line output from handles structure |
---|
| 97 | varargout{1} = handles.output; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | % --- Executes on selection change in list_element. |
---|
| 101 | function list_element_Callback(hObject, eventdata, handles) |
---|
| 102 | global t xs t_ref |
---|
| 103 | CurrentFile=get(handles.CurrentFile,'String'); |
---|
| 104 | bla=get(hObject,'String'); |
---|
| 105 | ind=get(hObject,'Value'); |
---|
| 106 | list=get(hObject,'UserData'); |
---|
| 107 | NewRootUid=list.uid(ind); |
---|
| 108 | heditxml=get(hObject,'Parent'); |
---|
| 109 | DataIn=get(heditxml,'UserData'); |
---|
| 110 | if ~isempty(xs) |
---|
| 111 | xs_node=list.xs_uid(ind);%xs_node of the subelement #ind |
---|
| 112 | [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node); |
---|
| 113 | [element,subelem]=get_xml(t,path,xs_element,NewRootUid,xs_subelem); |
---|
| 114 | update_list(handles,path,xs_element,element,NewRootUid,xs_subelem,subelem); |
---|
| 115 | if xs_element.subtest |
---|
| 116 | DataIn.CurrentUid=[DataIn.CurrentUid NewRootUid];%record new current uid |
---|
| 117 | DataIn.xs_CurrentUid=[DataIn.xs_CurrentUid xs_node];%record the new curent schema uid |
---|
| 118 | end |
---|
| 119 | |
---|
| 120 | % %update the import file display |
---|
| 121 | % if isfield(DataIn,'h_ref')&ishandle(DataIn.h_ref) |
---|
| 122 | % tag0_ref=find(t_ref,['/' path '/' xs_element.key]); |
---|
| 123 | % node_ref=list.index(ind); |
---|
| 124 | % if length(tag0_ref)<node_ref |
---|
| 125 | % node_ref=length(tag0_ref); |
---|
| 126 | % end |
---|
| 127 | % [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,node_ref,xs_subelem); |
---|
| 128 | % update_ref_list(DataIn.h_ref,xs_element,ref_element,node_ref,xs_subelem,ref_subelem); |
---|
| 129 | % end |
---|
| 130 | set(get(hObject,'Parent'),'UserData',DataIn); |
---|
| 131 | else%no schema |
---|
| 132 | [DataIn,testsimple]=displ_xml(handles,t,NewRootUid,DataIn,get(hObject,'parent')); |
---|
| 133 | if ~testsimple |
---|
| 134 | DataIn.CurrentUid=[DataIn.CurrentUid NewRootUid];%record new current uid |
---|
| 135 | set(get(hObject,'Parent'),'UserData',DataIn); |
---|
| 136 | end |
---|
| 137 | end |
---|
| 138 | |
---|
| 139 | %------------------------------------------------- |
---|
| 140 | % --- Executes on button press in move_up. |
---|
| 141 | function move_up_Callback(hObject, eventdata, handles) |
---|
| 142 | global t xs t_ref |
---|
| 143 | set(handles.export_list,'Value',1);% |
---|
| 144 | set(handles.export_list,'String','');% empty the export list |
---|
| 145 | CurrentFile=get(handles.CurrentFile,'String'); |
---|
| 146 | CurrentElement=get(handles.CurrentElement,'String'); |
---|
| 147 | heditxml=get(handles.move_up,'parent'); |
---|
| 148 | test_root=0; |
---|
| 149 | DataIn=get(heditxml,'UserData'); |
---|
| 150 | if isfield(DataIn,'CurrentUid')&length(DataIn.CurrentUid)>1 |
---|
| 151 | nodeup=DataIn.CurrentUid(end-1); |
---|
| 152 | DataIn.CurrentUid(end)=[]; |
---|
| 153 | else |
---|
| 154 | nodeup=[]; |
---|
| 155 | end |
---|
| 156 | if isempty(xs) |
---|
| 157 | if isempty(nodeup) |
---|
| 158 | test_root=1; |
---|
| 159 | else |
---|
| 160 | DataIn=displ_xml(handles,t,nodeup,DataIn,heditxml); |
---|
| 161 | end |
---|
| 162 | else |
---|
| 163 | xs_nodeup=[]; |
---|
| 164 | % if isfield(DataIn,'xs_UpUid') |
---|
| 165 | if isfield(DataIn,'xs_CurrentUid')&length(DataIn.xs_CurrentUid)>1 |
---|
| 166 | % xs_nodeup=DataIn.xs_UpUid |
---|
| 167 | xs_nodeup=DataIn.xs_CurrentUid(end-1); |
---|
| 168 | DataIn.xs_CurrentUid(end)=[];%uid of the root element in the schema |
---|
| 169 | end |
---|
| 170 | if isempty(xs_nodeup) |
---|
| 171 | test_root=1; |
---|
| 172 | else |
---|
| 173 | [xs_nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_nodeup); |
---|
| 174 | [element,subelem]=get_xml(t,path,xs_element,nodeup,xs_subelem); |
---|
| 175 | update_list(handles,path,xs_element,element,nodeup,xs_subelem,subelem); |
---|
| 176 | %update the import file display |
---|
| 177 | if isfield(DataIn,'h_ref')&ishandle(DataIn.h_ref) |
---|
| 178 | [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,nodeup,xs_subelem); |
---|
| 179 | update_ref_list(DataIn.h_ref,xs_element,ref_element,nodeup,xs_subelem,ref_subelem); |
---|
| 180 | end |
---|
| 181 | end |
---|
| 182 | set(get(hObject,'parent'),'UserData',DataIn); |
---|
| 183 | end |
---|
| 184 | if test_root% we are a the root, |
---|
| 185 | testupfile=0; |
---|
| 186 | DataIn=get(get(hObject,'parent'),'UserData'); |
---|
[55] | 187 | if isfield(DataIn,'UpFile')&&~isempty(DataIn.UpFile) |
---|
[2] | 188 | [UpPath,UpName,UpExt]=fileparts(DataIn.UpFile{1}); |
---|
| 189 | if isequal(UpExt,'.xml') |
---|
| 190 | set(handles.CurrentFile,'String',DataIn.UpFile{1}) |
---|
| 191 | CurrentFile_Callback(handles.CurrentFile,[],handles) |
---|
| 192 | testupfile=1; |
---|
| 193 | DataIn.UpFile{1}={}; |
---|
| 194 | end |
---|
| 195 | end |
---|
| 196 | if ~testupfile %open the browser |
---|
| 197 | RootPath=fileparts(CurrentFile); |
---|
| 198 | [FileName, PathName]=uigetfile( ... |
---|
| 199 | {'*.xml', '(*.xml)'; |
---|
| 200 | '*.xml', '.xml files '; ... |
---|
| 201 | '*.*', 'All Files (*.*)'}, ... |
---|
| 202 | 'Pick a file',RootPath); %file browser |
---|
| 203 | fileinput_new=fullfile(PathName,FileName); |
---|
| 204 | set(handles.CurrentFile,'String',fileinput_new) |
---|
| 205 | CurrentFile_Callback(handles.CurrentFile,[],handles) |
---|
| 206 | end |
---|
| 207 | end |
---|
| 208 | set(heditxml,'UserData',DataIn); |
---|
| 209 | %--------------------------------------------------------- |
---|
| 210 | %edit element value |
---|
| 211 | function element_value_Callback(hObject, eventdata, handles) |
---|
| 212 | %---------------------------------------------------------- |
---|
| 213 | global t xs |
---|
| 214 | if isequal(get(handles.element_value,'ForegroundColor'),[0.7 0.7 0.7]) |
---|
| 215 | return% edit element desactivated (grey display) |
---|
| 216 | end |
---|
| 217 | list_enum=get(handles.element_value,'String'); |
---|
| 218 | list_index=get(handles.element_value,'Value'); |
---|
| 219 | if iscell(list_enum) |
---|
| 220 | value=list_enum{list_index}; |
---|
| 221 | else |
---|
| 222 | value=list_enum; |
---|
| 223 | end |
---|
| 224 | heditxml=get(handles.element_value,'Parent'); |
---|
| 225 | DataIn=get(heditxml,'UserData'); |
---|
| 226 | %create the current root element if needed |
---|
| 227 | LengthElement=length(DataIn.CurrentUid); |
---|
| 228 | FilledUid=find(DataIn.CurrentUid~=0); |
---|
| 229 | LengthFilled=FilledUid(end); |
---|
| 230 | for irank=LengthFilled+1:LengthElement |
---|
| 231 | attrib=attributes(xs,'get',DataIn.xs_CurrentUid(irank),1); |
---|
| 232 | [t,DataIn.CurrentUid(irank)]=add(t,DataIn.CurrentUid(irank-1),'element',attrib.val); |
---|
| 233 | end |
---|
| 234 | node_element=get(handles.element_value,'UserData'); |
---|
| 235 | element_key=get(handles.element_key,'String'); |
---|
| 236 | t=set_element(t,DataIn.CurrentUid(end),node_element,element_key,value); |
---|
| 237 | |
---|
| 238 | set(heditxml,'UserData',DataIn) |
---|
| 239 | %update the current listing |
---|
| 240 | [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid(end)); |
---|
| 241 | [element,subelem]=get_xml(t,path,xs_element,DataIn.CurrentUid(end),xs_subelem); |
---|
| 242 | element_index=get(handles.list_element,'Value'); |
---|
| 243 | update_list(handles,path,xs_element,element,DataIn.CurrentUid(end),xs_subelem,subelem); |
---|
| 244 | set(handles.list_element,'Value',element_index); |
---|
| 245 | |
---|
| 246 | % |
---|
| 247 | % % --- Executes on button press in inport_file. |
---|
| 248 | % function inport_file_Callback(hObject, eventdata, handles) |
---|
| 249 | % CurrentFile=get(handles.RefFile,'String'); |
---|
| 250 | % if isempty(CurrentFile)|isequal(CurrentFile,'') |
---|
| 251 | % CurrentFile=get(handles.CurrentFile,'String') |
---|
| 252 | % end |
---|
| 253 | % [FileName, PathName]=uigetfile( ... |
---|
| 254 | % {'*.xml', '(*.xml)'; |
---|
| 255 | % '*.xml', '.xml files '; ... |
---|
| 256 | % '*.*', 'All Files (*.*)'}, ... |
---|
| 257 | % 'Pick a file',CurrentFile); %file browser |
---|
| 258 | % fileinput=fullfile(PathName,FileName); |
---|
| 259 | % sizf=size(fileinput); |
---|
| 260 | % if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end% keep only character strings as input file name |
---|
| 261 | % if exist(fileinput,'file') |
---|
| 262 | % set(handles.RefFile,'Visible','on') |
---|
| 263 | % set(handles.replicate,'Visible','on') |
---|
| 264 | % set(handles.RefFile,'String',fileinput) |
---|
| 265 | % RefFile_Callback(handles.RefFile, eventdata, handles) |
---|
| 266 | % end |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | %------------------------------------------------------ |
---|
| 270 | % --- Executes on button press in browser. |
---|
| 271 | function browser_Callback(hObject, eventdata, handles) |
---|
| 272 | %------------------------------------------------------- |
---|
| 273 | heditxml=get(hObject,'parent');%handle of the interface figure |
---|
| 274 | DataIn=get(heditxml,'UserData');%get the current input xml file |
---|
| 275 | CurrentFile=get(handles.CurrentFile,'String'); |
---|
| 276 | DataIn.Schema=[];%schema input file put to [] by default |
---|
| 277 | [FileName, PathName]=uigetfile( ... |
---|
| 278 | {'*.xml;*.xls','(*.xml,*.xls)'; |
---|
| 279 | '*.xml', '.xml files '; ... |
---|
| 280 | '*.xls', '.xls files '; ... |
---|
| 281 | '*.*', 'All Files (*.*)'}, ... |
---|
| 282 | 'Pick a file',CurrentFile); %file browser |
---|
| 283 | CurrentFile=fullfile(PathName,FileName); |
---|
| 284 | sizf=size(CurrentFile); |
---|
[55] | 285 | if (~ischar(CurrentFile)||~isequal(sizf(1),1)),return;end% keep only character strings as input file name |
---|
[2] | 286 | if exist(CurrentFile,'file') |
---|
| 287 | % set(handles.CurrentAttributes,'UserDataIn',PathName); %store the path to the xml file |
---|
| 288 | [CurPath,CurName,CurExt]=fileparts(CurrentFile); |
---|
| 289 | if isequal(CurExt,'.xls') |
---|
[55] | 290 | if isfield(DataIn,'hfig_xls') && ishandle(DataIn.hfig_xls) |
---|
[2] | 291 | [hfig_xls]=read_xls(CurrentFile,DataIn.hfig_xls); |
---|
| 292 | else |
---|
| 293 | [hfig_xls]=read_xls(CurrentFile); |
---|
| 294 | end |
---|
| 295 | figpos=get(heditxml,'Position'); |
---|
| 296 | newfigpos=[figpos(1)-0.25*figpos(3) figpos(2) 0.5*figpos(3) 0.5*figpos(4)]; |
---|
| 297 | set(hfig_xls,'Position',newfigpos) |
---|
| 298 | else |
---|
| 299 | set(handles.CurrentFile,'String',CurrentFile) |
---|
| 300 | CurrentFile_Callback(hObject, eventdata, handles) |
---|
| 301 | end |
---|
| 302 | end |
---|
| 303 | |
---|
| 304 | %------------------------------------ |
---|
| 305 | function CurrentFile_Callback(hObject, eventdata, handles) |
---|
| 306 | global t xs |
---|
| 307 | CurrentFile=get(handles.CurrentFile,'String'); |
---|
| 308 | heditxml=get(handles.CurrentFile,'parent');%handles of the inteface |
---|
| 309 | DataIn=get(heditxml,'UserData'); |
---|
| 310 | t=xmltree(CurrentFile);%open the xml file |
---|
| 311 | head_element=get(t,1); |
---|
[55] | 312 | if ~isfield(head_element,'name') || ~isfield(head_element,'attributes') |
---|
[42] | 313 | msgbox_uvmat('ERROR','root element of the .xml file not in correct format') |
---|
[2] | 314 | end |
---|
| 315 | head_name=head_element.name; |
---|
| 316 | head_attr=head_element.attributes;% attribute of root gives the name of the associated schema |
---|
| 317 | xstest=0; |
---|
| 318 | for iattr=1:length(head_attr) |
---|
[55] | 319 | if isequal(head_attr{iattr}.key,'xmlns:xsi')&& isequal(head_attr{iattr}.val,'none')%no schema to read |
---|
[2] | 320 | xs=[]; |
---|
| 321 | % xstest=1; |
---|
| 322 | end |
---|
[55] | 323 | if isequal(head_attr{iattr}.key,'xsi:noNamespaceSchemaLocation') && exist(head_attr{iattr}.val,'file') |
---|
[2] | 324 | DataIn.Schema=head_attr{iattr}.val; |
---|
| 325 | xs=xmltree(DataIn.Schema);%open the associated schema file |
---|
| 326 | xstest=1; |
---|
| 327 | end |
---|
| 328 | end |
---|
| 329 | if xstest==0 %look for the corresponding schema in the directory PARAM_LINUX.xml or PARAM_WIN.xml |
---|
| 330 | head_name=get(t,1,'name'); |
---|
| 331 | %Path to shemas: |
---|
[180] | 332 | % path_uvmat=which('editxml');% check the path detected for source file uvmat |
---|
| 333 | % path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
| 334 | % xmlparam=fullfile(path_UVMAT,'PARAM.xml'); |
---|
| 335 | xmlparam='PARAM.xml'; %will find PARAM.xml whose path is set in priority |
---|
[55] | 336 | if exist(xmlparam,'file') |
---|
| 337 | tparam=xmltree(xmlparam); |
---|
| 338 | sparam=convert(tparam); |
---|
| 339 | if isfield(sparam,'SchemaPath') |
---|
| 340 | schemafile=[fullfile(sparam.SchemaPath,head_name) '.xsd']; |
---|
| 341 | end |
---|
| 342 | if ~exist(schemafile,'file') |
---|
| 343 | schemafile=fullfile(path_UVMAT,schemafile);%look for relative path definition |
---|
| 344 | end |
---|
| 345 | if exist(schemafile,'file') |
---|
| 346 | xs=xmltree(schemafile); |
---|
[2] | 347 | else |
---|
[55] | 348 | msgbox_uvmat('ERROR',['The xml schema for ' CurrentFile ' is unknown, check the schema path set in the file PARAM.xml']) |
---|
| 349 | [FileName, PathName]=uigetfile( ... |
---|
| 350 | {'*.xsd', '(*.xsd)'; |
---|
| 351 | '*.xsd', '.xsd files '; ... |
---|
| 352 | '*.*', 'All Files (*.*)'}, ... |
---|
[180] | 353 | 'Pick a .xsd schema' ,schemafile); %file browser |
---|
[55] | 354 | if ischar(PathName) && ischar(FileName) && exist(fullfile(PathName,FileName),'file') |
---|
| 355 | DataIn.Schema=fullfile(PathName,FileName); |
---|
| 356 | xs=xmltree(DataIn.Schema);%open the associated schema file |
---|
| 357 | else |
---|
| 358 | xs=[]; |
---|
| 359 | end |
---|
[2] | 360 | end |
---|
| 361 | end |
---|
| 362 | end |
---|
| 363 | DataIn.CurrentUid=1; |
---|
| 364 | if isempty(xs) |
---|
| 365 | displ_xml(handles,t,1,DataIn,get(hObject,'parent'));%no associated schema, default display of the xml file |
---|
| 366 | else |
---|
| 367 | DataIn.xs_CurrentUid=find(xs,'/xs:schema/xs:element');%uid of the root element in the schema |
---|
| 368 | [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid);%scan the schema at the root level |
---|
| 369 | [element,subelem]=get_xml(t,path,xs_element,1,xs_subelem);% read the corresponding xml data |
---|
| 370 | update_list(handles,path,xs_element,element,1,xs_subelem,subelem);%update the display of information on the interface |
---|
| 371 | end |
---|
| 372 | set(heditxml,'UserData',DataIn);%store the new input xml file name |
---|
| 373 | |
---|
| 374 | %------------------------------------------------------- |
---|
| 375 | % function scan_schema: read the xml schema xs |
---|
| 376 | %-------------------------------------------------------- |
---|
| 377 | %OUTPUT: |
---|
| 378 | %nodeup: parent node of nodeinput |
---|
| 379 | %path: path to nodeinput in the tree |
---|
| 380 | %xs_element: element corresponding to nodeinput |
---|
| 381 | %xs_element.uid, =tag of the element in the schema (=nodeinput) |
---|
| 382 | %xs_element.key: key label of nodeinput |
---|
| 383 | %xs_element.type: type of data contained in the element |
---|
| 384 | %xs_element.annot: annotation of nodeinput |
---|
| 385 | %xs_element.attrib: list of accepted attributes keys for xs_element |
---|
| 386 | %xs_element.enum: enumeration, list of accepted values for nodeinput |
---|
| 387 | %xs_element.subtest: =1 if the element contains subelements in the schema, 0 else |
---|
| 388 | |
---|
| 389 | %xs_subelement(k): subelement #k of xs_element |
---|
| 390 | %xs_subelem(k).node: node number in the schema |
---|
| 391 | %xs_subelem(k).key: key name of the element |
---|
| 392 | %xs_subelem(k).testsub: =1 if element contains subelements, 0 else |
---|
| 393 | %xs_subelem(k).minOccurs: =0 for a non mandatory element, =1 else |
---|
| 394 | %xs_subelem(k).maxOccurs |
---|
| 395 | % |
---|
| 396 | %INPUT: |
---|
| 397 | %xs: schema xml tree |
---|
| 398 | %nodeinput: tag of the current root element in the schema |
---|
| 399 | function [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,nodeinput) |
---|
| 400 | nodeup=[]; |
---|
| 401 | path=[]; |
---|
| 402 | xs_element.key=[]; |
---|
| 403 | xs_element.type=[]; |
---|
| 404 | xs_element.annot=[]; |
---|
| 405 | xs_element.attrib=[]; |
---|
| 406 | xs_element.subtest=0; |
---|
| 407 | xs_element.enum={}; |
---|
| 408 | xs_subelem=[];%default |
---|
| 409 | % get default nodeinput (root of the file) if not defined |
---|
| 410 | if ~exist('nodeinput') | isempty(nodeinput)% we start at the root |
---|
| 411 | node=find(xs,'/xs:schema/xs:element');%description of the root element |
---|
| 412 | else |
---|
| 413 | node=nodeinput; |
---|
| 414 | end |
---|
| 415 | xs_element.uid=node; |
---|
| 416 | %get the key name and element_type of the element |
---|
| 417 | node_content=get(xs,node); |
---|
| 418 | if isempty(node_content),return,end; |
---|
| 419 | if ~isempty(node_content) & isfield(node_content,'attributes') |
---|
| 420 | attrib=node_content.attributes; |
---|
| 421 | for iattr=1:length(attrib) |
---|
| 422 | struct=attrib{iattr}; |
---|
| 423 | if isequal(struct.key,'name') |
---|
| 424 | xs_element.key=struct.val; % read element key name |
---|
| 425 | elseif isequal(struct.key,'type') |
---|
| 426 | xs_element.type=struct.val; % read element key name |
---|
| 427 | end |
---|
| 428 | end |
---|
| 429 | end |
---|
| 430 | |
---|
| 431 | %get the parent node of nodeinput |
---|
| 432 | if ~isempty(node_content) |
---|
| 433 | nodeup=get(xs,node,'parent');%move up to the parent in the tree |
---|
| 434 | if ~isempty(nodeup) |
---|
| 435 | nodeup=get(xs,nodeup(1),'parent');%move up to the parent in the tree |
---|
| 436 | if isequal(nodeup,[]) |
---|
| 437 | %OUVRIR FICHIER AMONT |
---|
| 438 | up=0; |
---|
| 439 | else |
---|
| 440 | nodeup=get(xs,nodeup(1),'parent');%move up to the parent in the tree |
---|
| 441 | end |
---|
| 442 | end |
---|
| 443 | end |
---|
| 444 | %get the path to 'nodeinput' in the schema |
---|
| 445 | up=1; |
---|
| 446 | path=[]; |
---|
| 447 | if ~isempty(nodeup) |
---|
| 448 | attrib=attributes(xs,'get',nodeup,1); |
---|
| 449 | path=attrib.val; |
---|
| 450 | nodeup2=nodeup; |
---|
| 451 | while up==1; |
---|
| 452 | nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree |
---|
| 453 | nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree |
---|
| 454 | if isempty(nodeup2) |
---|
| 455 | up=0; |
---|
| 456 | else |
---|
| 457 | nodeup2=get(xs,nodeup2(1),'parent');%move up to the parent in the tree |
---|
| 458 | if isempty(nodeup2) |
---|
| 459 | up=0; |
---|
| 460 | else |
---|
| 461 | attrib=attributes(xs,'get',nodeup2,1); |
---|
| 462 | path=[attrib.val '/' path]; |
---|
| 463 | end |
---|
| 464 | end |
---|
| 465 | end |
---|
| 466 | end |
---|
| 467 | |
---|
| 468 | %explore the subtree in the schema file |
---|
| 469 | node1=children(xs,node); %find the children of the root element |
---|
| 470 | test_sub=0; %no subtree in the .xml file by default |
---|
| 471 | comment=''; |
---|
| 472 | element={}; |
---|
| 473 | minOccurs={}; |
---|
| 474 | maxOccurs={}; |
---|
| 475 | testsub={}; |
---|
| 476 | list_menu={}; |
---|
| 477 | text={}; |
---|
| 478 | if ~isempty(node1) |
---|
| 479 | for i=1:length(node1) |
---|
| 480 | nodename1=get(xs,node1(i),'name'); |
---|
| 481 | node2=children(xs,node1(i)); |
---|
| 482 | if isequal(nodename1,'xs:annotation') |
---|
| 483 | for j=1:length(node2) |
---|
| 484 | nodename2=get(xs,node2(j),'name'); |
---|
| 485 | if isequal(nodename2,'xs:documentation') |
---|
| 486 | node3=children(xs,node2(j)); |
---|
| 487 | xs_element.annot=get(xs,node3,'value');%read annotation |
---|
| 488 | end |
---|
| 489 | end |
---|
| 490 | % pour les elements |
---|
| 491 | elseif isequal(nodename1,'xs:simpleType') |
---|
| 492 | for j=1:length(node2) |
---|
| 493 | nodename2=get(xs,node2(j),'name'); |
---|
| 494 | if isequal(nodename2,'xs:restriction') |
---|
| 495 | node3=children(xs,node2(j)); |
---|
| 496 | for k=1:length(node3) |
---|
| 497 | nodename3=get(xs,node3(k),'name'); |
---|
| 498 | if isequal(nodename3,'xs:enumeration') |
---|
| 499 | node3_content=get(xs,node3(k)); |
---|
| 500 | attr=node3_content.attributes; |
---|
| 501 | for m=1:length(attr) |
---|
| 502 | struct=attr{m}; |
---|
| 503 | if isequal(struct.key,'value') |
---|
| 504 | xs_element.enum{k}=struct.val; % read enumeration |
---|
| 505 | end |
---|
| 506 | end |
---|
| 507 | end |
---|
| 508 | end |
---|
| 509 | end |
---|
| 510 | end |
---|
| 511 | elseif isequal(nodename1,'xs:complexType') |
---|
| 512 | for j=1:length(node2) |
---|
| 513 | nodename2=get(xs,node2(j),'name'); |
---|
| 514 | if isequal(nodename2,'xs:attribute') |
---|
| 515 | node_content=get(xs,node2(j)); |
---|
| 516 | attr=node_content.attributes; |
---|
| 517 | for k=1:length(attr) |
---|
| 518 | struct=attr{k};%read attributes |
---|
| 519 | if isequal(struct.key,'name') |
---|
| 520 | xs_element.attrib=struct.val; %read attributes of main node |
---|
| 521 | end |
---|
| 522 | end |
---|
| 523 | elseif isequal(nodename2,'xs:sequence') |
---|
| 524 | xs_element.subtest=1; |
---|
| 525 | node3=children(xs,node2(j));%nodes of the sequence |
---|
| 526 | for k=1:length(node3) |
---|
| 527 | xs_subelem(k).node=node3(k); |
---|
| 528 | xs_subelem(k).testsub=0;%default |
---|
| 529 | node_content=get(xs,node3(k)); |
---|
| 530 | xs_subelem(k).minOccurs=1; %default |
---|
| 531 | xs_subelem(k).maxOccurs=1; %default |
---|
| 532 | % pref{k}=[]; %default |
---|
| 533 | if isequal(node_content.name,'xs:element') |
---|
| 534 | attr=node_content.attributes; |
---|
| 535 | % attr{:}.key |
---|
| 536 | for l=1:length(attr) |
---|
| 537 | if isequal(attr{l}.key,'name') |
---|
| 538 | xs_subelem(k).key=attr{l}.val;%name of the element |
---|
| 539 | elseif isequal(attr{l}.key, 'minOccurs') |
---|
| 540 | xs_subelem(k).minOccurs=attr{l}.val; |
---|
| 541 | elseif isequal(attr{l}.key, 'maxOccurs') |
---|
| 542 | xs_subelem(k).maxOccurs=attr{l}.val; |
---|
| 543 | end |
---|
| 544 | end |
---|
| 545 | end |
---|
| 546 | node4=children(xs,node3(k)); |
---|
| 547 | for l=1:length(node4) |
---|
| 548 | res=get(xs,node4(l),'name'); |
---|
| 549 | if isequal(res,'xs:complexType')%look whether the element k contains a subtree |
---|
| 550 | node5=children(xs,node4(l)); |
---|
| 551 | for m=1:length(node5) |
---|
| 552 | res2=get(xs,node5(m),'name'); |
---|
| 553 | if isequal(res2,'xs:sequence') |
---|
| 554 | xs_subelem(k).testsub=1; %flag for the existence of a subtree |
---|
| 555 | end |
---|
| 556 | end |
---|
| 557 | end |
---|
| 558 | end |
---|
| 559 | end |
---|
| 560 | |
---|
| 561 | end |
---|
| 562 | end |
---|
| 563 | end |
---|
| 564 | end |
---|
| 565 | end |
---|
| 566 | % look for predefined types |
---|
| 567 | if length(xs_element.type)>=3 & (xs_element.type([1:3])~='xs:') |
---|
| 568 | node_type=find(xs,'/xs:schema/xs:simpleType') |
---|
| 569 | for i=1:length(node_type) |
---|
| 570 | content=get(xs,node_type(i)); |
---|
| 571 | nodeattr=content.attributes; |
---|
| 572 | if ~isempty(nodeattr) & isequal(nodeattr{1}.key,'name') & isequal(nodeattr{1}.val,xs_element.type) |
---|
| 573 | node1=children(xs,node_type(i)); |
---|
| 574 | node2=find(xs,node1,'name','xs:restriction'); |
---|
| 575 | % nodename1=find(xs, |
---|
| 576 | node3=children(xs,node2); |
---|
| 577 | node4=find(xs,node3,'name','xs:enumeration'); |
---|
| 578 | for ienum=1:length(node4) |
---|
| 579 | struct2=get(xs,node4(ienum)); |
---|
| 580 | enumval=struct2.attributes; |
---|
| 581 | xs_element.enum{ienum}=enumval{1}.val; |
---|
| 582 | end |
---|
| 583 | end |
---|
| 584 | end |
---|
| 585 | end |
---|
| 586 | |
---|
| 587 | %-------------------------------------------------------- |
---|
| 588 | %OUTPUT: |
---|
| 589 | %element.val: value of the current element, =[] in the absence of chardata value |
---|
| 590 | %node: node (iud) of the element in t |
---|
| 591 | %element.attr_key{iattr}: attribute key #iattr of the current element |
---|
| 592 | %element.attr_val{iattr}: attribute value #iattr of the current element |
---|
| 593 | %element.attrup: %structure containing the attributes of the element, including the ones unheritated from parent nodes |
---|
| 594 | %subelem(iline).val : value of subelement # iline, concatenated with corresponding attributes |
---|
| 595 | %subelem(iline).xsindex: index k of the subelement #iline in the list xs_subelem of the schema |
---|
| 596 | %subelem(iline).index: index of the subelement #iline inside its xs_subelement, =0 when the xs_subelement is absent in t |
---|
| 597 | |
---|
| 598 | %INPUT: |
---|
| 599 | %t: xml tree |
---|
| 600 | %path: path to the current element in the schema |
---|
| 601 | %xs_element: current element in the schema |
---|
| 602 | %xs_element.key: key label |
---|
| 603 | %xs_element.type: type of data contained in the element |
---|
| 604 | %xs_element.annot: annotation of nodeinput |
---|
| 605 | %xs_element.attrib: list of accepted attributes keys for xs_element |
---|
| 606 | %xs_element.enum: enumeration, list of accepted values |
---|
| 607 | %xs_element.subtest: =1 if the element contains subelements in the schema, 0 else |
---|
| 608 | %index: index of the element, =1 in case of single occurence in xs_element,=0 in case of missing element |
---|
| 609 | %xs_subelem(k): subelement #k of the current element in the schema |
---|
| 610 | %xs_subelem(k).node: node iud of the |
---|
| 611 | %xs_subelem(k).key: key name of the subelement #k in the schema |
---|
| 612 | %xs_subelem(k).testsub: =1 if element contains subelements, 0 else |
---|
| 613 | %xs_subelem(k).minOccurs |
---|
| 614 | %xs_subelem(k).maxOccurs |
---|
| 615 | |
---|
| 616 | function [element,subelem]=get_xml(t,path,xs_element,node,xs_subelem) |
---|
| 617 | element.attr_key='';%default |
---|
| 618 | element.attr_val='';%default |
---|
| 619 | element.val=''; |
---|
| 620 | % element.type=''; |
---|
| 621 | % element.testmanual=testmanual %inheritates the input manual editing flag by default |
---|
| 622 | subelem=[]; %default |
---|
| 623 | attrup=[]; |
---|
| 624 | % node=[]; |
---|
| 625 | |
---|
| 626 | % %find the element properties in the xml file |
---|
| 627 | if node >= 1 |
---|
| 628 | elem_struct=get(t,node); |
---|
| 629 | if ~xs_element.subtest |
---|
| 630 | elem_contents=get(t,elem_struct.contents); |
---|
| 631 | if isempty(elem_contents) |
---|
| 632 | element.val=[]; |
---|
| 633 | else |
---|
| 634 | element.val=elem_contents.value |
---|
| 635 | end |
---|
| 636 | end |
---|
| 637 | if isfield(elem_struct,'attributes') |
---|
| 638 | elem_attr=elem_struct.attributes; |
---|
| 639 | for iattr=1:length(elem_attr) |
---|
| 640 | element.attr_key{iattr}=elem_attr{iattr}.key ; |
---|
| 641 | element.attr_val{iattr}=elem_attr{iattr}.val; |
---|
| 642 | % attrup=setfield(attrup,elem_attr{iattr}.key,elem_attr{iattr}.val); |
---|
| 643 | breakdetect=find(elem_attr{iattr}.key=='/'| elem_attr{iattr}.key==':'| elem_attr{iattr}.key=='.');% find '/' |
---|
| 644 | if isempty(breakdetect) |
---|
| 645 | % comline=['attrup.' elem_attr{iattr}.key '=' elem_attr{iattr}.val ';'] |
---|
| 646 | eval(['attrup.' elem_attr{iattr}.key '=''' elem_attr{iattr}.val ''';']) |
---|
| 647 | end |
---|
| 648 | end |
---|
| 649 | end |
---|
| 650 | end |
---|
| 651 | %get the parent node attributes |
---|
| 652 | up=1; |
---|
| 653 | if node>0 |
---|
| 654 | nodeup=node; |
---|
| 655 | while up==1; |
---|
| 656 | nodeup=get(t,nodeup,'parent');%move up to the parent in the tree |
---|
| 657 | if isempty(nodeup) |
---|
| 658 | up=0; |
---|
| 659 | else |
---|
| 660 | nodeup_content=get(t,nodeup); |
---|
| 661 | attrib=nodeup_content.attributes; |
---|
| 662 | for iattr=1:length(attrib) |
---|
| 663 | key=attrib{iattr}.key; |
---|
| 664 | breakdetect=find(key=='/'| key==':'| key=='.');% find '/' |
---|
| 665 | if ~isfield(attrup,key) & isempty(breakdetect) |
---|
| 666 | eval(['attrup.' key '=''' attrib{iattr}.val ''';']) |
---|
| 667 | end |
---|
| 668 | end |
---|
| 669 | end |
---|
| 670 | end |
---|
| 671 | element.attrup=attrup; |
---|
| 672 | end |
---|
| 673 | %find the subelement properties in the xml file |
---|
| 674 | if xs_element.subtest |
---|
| 675 | iline=0; |
---|
| 676 | for k=1:length(xs_subelem)%node2: list of subelements in the sub-sequence |
---|
| 677 | % attr=attributes(xs,'get',node2(i),1);% |
---|
| 678 | % element=attr.val;%name of the element |
---|
| 679 | tag=find(t,['/' path '/' xs_element.key '/' xs_subelem(k).key]);%look for the corresponding element node in the .xml tree |
---|
| 680 | struct_element=get(t,tag);%get the content of the element |
---|
| 681 | if isempty(struct_element) |
---|
| 682 | iline=iline+1; |
---|
| 683 | subelem(iline).uid=0; |
---|
| 684 | subelem(iline).xsindex=k; |
---|
| 685 | subelem(iline).index=0; |
---|
| 686 | % subelem(iline).testmanual=element.testmanual;% inheritates the manual editing flag by default |
---|
| 687 | if isequal(xs_subelem(k).minOccurs,'0') |
---|
| 688 | subelem(iline).val='[]';%element value not mandatory in the schema |
---|
| 689 | else |
---|
| 690 | subelem(iline).val='[MISSING]';%element value mandatory in the schema |
---|
| 691 | end |
---|
| 692 | % subelem(iline).attrup=attrup; %inheritated attributes |
---|
| 693 | elseif isequal(length(struct_element),1) |
---|
| 694 | contents=get(t,struct_element.contents); |
---|
| 695 | iline=iline+1; |
---|
| 696 | subelem(iline).uid=tag; |
---|
| 697 | subelem(iline).xsindex=k; |
---|
| 698 | subelem(iline).index=1; |
---|
| 699 | % subelem(iline).testmanual=element.testmanual;% |
---|
| 700 | if isfield(contents,'value') & ~isempty(contents.value) |
---|
| 701 | subelem(iline).val=contents.value; |
---|
| 702 | elseif xs_subelem(k).testsub |
---|
| 703 | subelem(iline).val=''; |
---|
| 704 | elseif isequal(xs_subelem(k).minOccurs,0) |
---|
| 705 | subelem(iline).val='[]';%element value not mandatory in the schema |
---|
| 706 | else |
---|
| 707 | subelem(iline).val='[MISSING]';%element value mandatory in the schema |
---|
| 708 | end |
---|
| 709 | % subelem(iline).attrup=attrup; %inheritated attributes |
---|
| 710 | if isfield(struct_element,'attributes') |
---|
| 711 | element_attr=struct_element.attributes; |
---|
| 712 | attr_display=[]; |
---|
| 713 | for iattr=1:length(element_attr) |
---|
| 714 | % attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 715 | subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 716 | % subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val); |
---|
| 717 | end |
---|
| 718 | end |
---|
| 719 | else%case of a multiple element |
---|
| 720 | for subindex=1:length(struct_element) |
---|
| 721 | contents=get(t,struct_element{subindex}.contents); |
---|
| 722 | iline=iline+1; |
---|
| 723 | subelem(iline).index=subindex;%index of the element |
---|
| 724 | subelem(iline).xsindex=k; |
---|
| 725 | % subelem(iline).testmanual=element.testmanual;% |
---|
| 726 | if isfield(contents,'value')& ~isempty(contents.value) |
---|
| 727 | subelem(iline).val=contents.value; |
---|
| 728 | elseif xs_subelem(k).testsub |
---|
| 729 | subelem(iline).val=''; |
---|
| 730 | else |
---|
| 731 | subelem(iline).val='[]'; |
---|
| 732 | end |
---|
| 733 | % subelem(iline).attrup=attrup; %inheritated attributes |
---|
| 734 | if isfield(struct_element{subindex},'attributes') |
---|
| 735 | element_attr=struct_element{subindex}.attributes; |
---|
| 736 | attr_display=[]; |
---|
| 737 | for iattr=1:length(element_attr) |
---|
| 738 | % attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 739 | subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 740 | % subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val); |
---|
| 741 | end |
---|
| 742 | end |
---|
| 743 | end |
---|
| 744 | end |
---|
| 745 | end |
---|
| 746 | end |
---|
| 747 | |
---|
| 748 | %------------------------------------- |
---|
| 749 | %updates the interface |
---|
| 750 | function update_list(handles,path,xs_element,element,node,xs_subelem,subelem) |
---|
| 751 | %----------------------------- |
---|
| 752 | if xs_element.subtest% we list the sub-elements of root |
---|
| 753 | set(handles.export_list,'Value',1) |
---|
| 754 | set(handles.export_list,'String','')%flush the export list |
---|
| 755 | set(handles.CurrentElement,'String',[path '/' xs_element.key]) |
---|
| 756 | % title_element.key=[path '/' xs_element.key]; |
---|
| 757 | % if ~isempty(path) |
---|
| 758 | % xsnode_index=get(handles.list_element,'UserDataIn'); |
---|
| 759 | % ind=get(handles.list_element,'Value'); |
---|
| 760 | % title_element.index=xsnode_index(2,ind); |
---|
| 761 | % else |
---|
| 762 | % title_element.index=1; |
---|
| 763 | % end |
---|
| 764 | % title_element.xsnode=xs_element.uid; |
---|
| 765 | % title_element.node=node; |
---|
| 766 | % set(handles.CurrentFile,'UserDataIn',title_element)%element corresponding to the title |
---|
| 767 | set(handles.CurrentAnnotation,'String',xs_element.annot) |
---|
| 768 | attr_col=[]; |
---|
| 769 | testedit=0;% cannot edit elements by default |
---|
| 770 | for iattr=1:length(element.attr_key) |
---|
| 771 | % if isequal(element.attr_key{iattr},'source') & isequal(element.attr_val{iattr},'manual') |
---|
| 772 | % testedit=1; |
---|
| 773 | % end |
---|
| 774 | attr_col=strvcat(attr_col,[element.attr_key{iattr} ' = ' element.attr_val{iattr}]); |
---|
| 775 | end |
---|
| 776 | set(handles.CurrentAttributes,'String',attr_col) |
---|
| 777 | pref_col=''; |
---|
| 778 | key_col=''; |
---|
| 779 | equal_sign=''; |
---|
| 780 | val_col=''; |
---|
| 781 | for iline=1:length(subelem) |
---|
| 782 | xsindex=subelem(iline).xsindex; |
---|
| 783 | index(iline)=subelem(iline).index; |
---|
| 784 | subuid=subelem(iline).uid; |
---|
| 785 | if isempty(subuid) |
---|
| 786 | list.uid(iline)=0; |
---|
| 787 | else |
---|
| 788 | list.uid(iline)=subuid; |
---|
| 789 | end |
---|
| 790 | node(iline)=xs_subelem(xsindex).node; |
---|
| 791 | % testmanual(iline)=subelem(iline).testmanual; |
---|
| 792 | ikey=xs_subelem(xsindex).key; |
---|
| 793 | if xs_subelem(xsindex).testsub |
---|
| 794 | ival=[' + ' subelem(iline).val]; |
---|
| 795 | else |
---|
| 796 | ival=[' = ' subelem(iline).val]; |
---|
| 797 | end |
---|
| 798 | key_col=strvcat(key_col,ikey); |
---|
| 799 | val_col=strvcat(val_col,ival); |
---|
| 800 | end |
---|
| 801 | list_element=[key_col val_col]; |
---|
| 802 | set(handles.list_element,'String',list_element) |
---|
| 803 | set(handles.list_element,'Value',1) |
---|
| 804 | list.xs_uid=node; |
---|
| 805 | list.index=index; |
---|
| 806 | set(handles.list_element,'UserData',list) |
---|
| 807 | set(handles.element_attrib,'Visible','off') |
---|
| 808 | set(handles.element_key,'Visible','off') |
---|
| 809 | set(handles.element_value,'Visible','off') |
---|
| 810 | else % we edit an element |
---|
| 811 | |
---|
| 812 | export_list=get(handles.export_list,'String');%export list |
---|
| 813 | testadd=1; |
---|
| 814 | for ilist=1:length(export_list) |
---|
| 815 | if isequal(xs_element.key,export_list{ilist}) |
---|
| 816 | testadd=0; |
---|
| 817 | break |
---|
| 818 | end |
---|
| 819 | end |
---|
| 820 | if testadd |
---|
| 821 | export_list=[export_list;{xs_element.key}]; |
---|
| 822 | ilist=length(export_list); |
---|
| 823 | end |
---|
| 824 | set(handles.export_list,'String',export_list) |
---|
| 825 | if iscell(element.val) |
---|
| 826 | element_val=element.val{1}; |
---|
| 827 | else |
---|
| 828 | element_val=element.val; |
---|
| 829 | end |
---|
| 830 | set(handles.element_value,'String',element_val) |
---|
| 831 | export_val=get(handles.export_list,'UserData'); |
---|
| 832 | export_val{ilist}=element_val; |
---|
| 833 | set(handles.export_list,'UserData',export_val); |
---|
| 834 | set(handles.element_annot,'String',xs_element.annot) |
---|
| 835 | set(handles.element_type,'String',['type: ' xs_element.type]) |
---|
| 836 | attr_col=[]; |
---|
| 837 | testedit=0;% cannot edit element by default |
---|
| 838 | for iattr=1:length(element.attr_key) |
---|
| 839 | % if isequal(element.attr_key{iattr},'source') & isequal(element.attr_val{iattr},'manual') |
---|
| 840 | % testedit=1; |
---|
| 841 | % end |
---|
| 842 | attr_col=strvcat(attr_col,[element.attr_key{iattr} ' = ' element.attr_val{iattr}]); |
---|
| 843 | end |
---|
| 844 | set(handles.element_attrib,'String',attr_col) |
---|
| 845 | set(handles.element_key,'String',xs_element.key) |
---|
| 846 | |
---|
| 847 | |
---|
| 848 | if isempty(xs_element.enum) |
---|
| 849 | set(handles.element_value,'Value',1) |
---|
| 850 | set(handles.element_value,'Style','edit') |
---|
| 851 | else % case of an enumeration of possible values |
---|
| 852 | list_enum=[]; |
---|
| 853 | list_val=[]; |
---|
| 854 | for ienum=1:length(xs_element.enum) |
---|
| 855 | list_enum{ienum,1}=xs_element.enum{ienum}; |
---|
| 856 | if isequal(xs_element.enum{ienum},element_val) |
---|
| 857 | list_val=ienum; |
---|
| 858 | end |
---|
| 859 | end |
---|
| 860 | if isempty(list_val) |
---|
| 861 | list_enum{length(xs_element.enum)+1,1}=['[' element_val ']'];%show the non-valid element between brackets |
---|
| 862 | list_val=length(xs_element.enum)+1; |
---|
| 863 | end |
---|
| 864 | set(handles.element_value,'Style','popupmenu') |
---|
| 865 | set(handles.element_value,'String',list_enum) |
---|
| 866 | set(handles.element_value,'Value',list_val) |
---|
| 867 | end |
---|
| 868 | if isempty(element.val) |
---|
| 869 | testedit=1;%allow element editing if value is missing |
---|
| 870 | end |
---|
| 871 | set(handles.element_attrib,'Visible','On') |
---|
| 872 | set(handles.element_key,'Visible','On') |
---|
| 873 | set(handles.element_value,'Visible','On') |
---|
| 874 | end |
---|
| 875 | set(handles.element_value,'UserData',node) |
---|
[55] | 876 | if ~testedit && isfield(element,'attrup') && isfield(element.attrup,'source')&& ~isequal(element.attrup.source,'manual') |
---|
[2] | 877 | set(handles.element_value,'Enable','inactive') |
---|
| 878 | else |
---|
| 879 | set(handles.element_value,'Enable','on') |
---|
| 880 | end |
---|
| 881 | |
---|
| 882 | |
---|
| 883 | % --- Executes on button press in SAVE. |
---|
| 884 | function SAVE_Callback(hObject, eventdata, handles) |
---|
| 885 | global t |
---|
| 886 | DataIn=get(get(handles.SAVE,'parent'),'UserData'); |
---|
| 887 | CurrentFile=get(handles.CurrentFile,'String'); |
---|
| 888 | if isfield(DataIn,'Schema') |
---|
| 889 | if ~isempty(DataIn.Schema)% update ref to schema |
---|
| 890 | attrxsd=attributes(t,'get',1); |
---|
| 891 | setest=0; |
---|
| 892 | for iattr=1:length(attrxsd) |
---|
| 893 | if isequal(attrxsd{iattr}.key,'xsi:noNamespaceSchemaLocation') |
---|
| 894 | t= attributes(t,'set',1,iattr,'xsi:noNamespaceSchemaLocation',DataIn.Schema); |
---|
| 895 | setest=1; |
---|
| 896 | end |
---|
| 897 | end |
---|
| 898 | if setest==0; |
---|
| 899 | t=attributes(t,'add',1,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance'); |
---|
| 900 | t= attributes(t,'add',1,'xsi:noNamespaceSchemaLocation',DataIn.Schema); |
---|
| 901 | end |
---|
| 902 | end |
---|
| 903 | end |
---|
| 904 | copyfile(CurrentFile,[CurrentFile '.bak']); |
---|
| 905 | save(t,CurrentFile); |
---|
| 906 | |
---|
| 907 | %------------------------------------- |
---|
| 908 | % creates and/or set values to an element in t |
---|
| 909 | %t: xml tree |
---|
| 910 | %RootUid: uid of t under which we introduce an element |
---|
| 911 | %node: uid of the element that we correct, if =0, a new element is created |
---|
| 912 | %key: key name of the element |
---|
| 913 | %value: new value of the element |
---|
| 914 | function t=set_element(t,RootUid,node,key,value) |
---|
| 915 | %create the subelement if needed |
---|
| 916 | if isequal(node,0) |
---|
| 917 | [t,node]= add(t,RootUid,'element',key); |
---|
| 918 | end |
---|
| 919 | node_chardata=children(t,node); %corresponding data node |
---|
| 920 | if isempty(node_chardata)%if the data does not exist in t, create it |
---|
| 921 | t=add(t,node,'chardata',value); |
---|
| 922 | elseif isequal(length(node_chardata),1)&isequal(get(t,node_chardata,'type'),'chardata')% update only a simple element with 'chardata' |
---|
| 923 | t=set(t,node_chardata,'value',value);%modify existing data |
---|
| 924 | end |
---|
| 925 | attr=attributes(t,'get',node); |
---|
| 926 | if isempty(attr) |
---|
| 927 | t=attributes(t,'add',node,'source','manual');%indicate a manual eidting |
---|
| 928 | end |
---|
| 929 | |
---|
| 930 | % --- Executes on selection change in element_attr_val. |
---|
| 931 | function element_attr_val_Callback(hObject, eventdata, handles) |
---|
| 932 | % hObject handle to element_attr_val (see GCBO) |
---|
| 933 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 934 | % handles structure with handles and user data (see GUIDATA) |
---|
| 935 | |
---|
| 936 | % Hints: contents = get(hObject,'String') returns element_attr_val contents as cell array |
---|
| 937 | % contents{get(hObject,'Value')} returns selected item from element_attr_val |
---|
| 938 | |
---|
| 939 | |
---|
| 940 | % --- Executes on button press in ADD. |
---|
| 941 | function ADD_Callback(hObject, eventdata, handles) |
---|
| 942 | % hObject handle to ADD (see GCBO) |
---|
| 943 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 944 | % handles structure with handles and user data (see GUIDATA) |
---|
| 945 | |
---|
| 946 | %---------------------------------------- |
---|
| 947 | %read an xml file without schema |
---|
| 948 | function [Data,testsimple]=displ_xml(handles,t,root_uid,DataIn,heditxml) |
---|
| 949 | Data=DataIn;%default |
---|
| 950 | if ~isfield(Data,'CurrentUid') |
---|
| 951 | Data.CurrentUid=[]; |
---|
| 952 | end |
---|
| 953 | CurrentFile=get(handles.CurrentFile,'String'); |
---|
| 954 | |
---|
| 955 | %display the current element |
---|
| 956 | root_element=get(t,root_uid); |
---|
| 957 | uidparent=root_uid; |
---|
| 958 | if isfield(root_element,'name') |
---|
| 959 | CurrentElement=root_element.name; |
---|
| 960 | while ~isequal(uidparent,1)%while the first level has not been reached |
---|
| 961 | uidparent=parent(t,uidparent); |
---|
| 962 | dirdat=get(t,uidparent); |
---|
| 963 | if isfield(dirdat,'name') |
---|
| 964 | CurrentElement=[dirdat.name '/' CurrentElement]; |
---|
| 965 | end |
---|
| 966 | end |
---|
| 967 | set(handles.CurrentElement,'String',CurrentElement) |
---|
| 968 | end |
---|
| 969 | list_uid=children(t,root_uid); |
---|
| 970 | %case of a single element |
---|
| 971 | testsimple=0; |
---|
| 972 | filedat=[]; |
---|
| 973 | if ~isempty(list_uid) |
---|
| 974 | filedat=get(t,list_uid(1)) |
---|
| 975 | if isfield(filedat,'type') & isequal(filedat.type,'chardata') &isfield(filedat,'value') |
---|
| 976 | testsimple=1;%simple element |
---|
| 977 | end |
---|
| 978 | end |
---|
| 979 | |
---|
| 980 | %attributes of the current element |
---|
| 981 | nbattrib= attributes(t,'length',root_uid); |
---|
| 982 | testopen=0; |
---|
| 983 | attr_col=[]; |
---|
| 984 | for iattr=1:nbattrib |
---|
| 985 | attr= attributes(t,'get',root_uid,iattr); |
---|
| 986 | if isequal(attr.key,'source')% look for 'source' attribute |
---|
| 987 | if isequal(attr.val,'file')%if the source is 'file', look for the path and open it |
---|
| 988 | if isfield(filedat,'type') & isequal(filedat.type,'chardata') &isfield(filedat,'value') |
---|
| 989 | cur_file=filedat.value; |
---|
| 990 | uidparent=root_uid;%initialization |
---|
| 991 | while ~isequal(uidparent,1)%while the first level has not been reached |
---|
| 992 | uidparent=parent(t,uidparent); |
---|
| 993 | dirdat=get(t,uidparent); |
---|
| 994 | if isfield(dirdat,'type') & isequal(dirdat.type,'element') & isfield(dirdat,'name') |
---|
| 995 | nbattrib_up= attributes(t,'length',uidparent); |
---|
| 996 | for iattr_up=1:nbattrib_up |
---|
| 997 | attr= attributes(t,'get',uidparent,iattr_up); |
---|
| 998 | % if isequal(attr.key,'source')&isequal(attr.val,'directory')% look for 'source' attribute |
---|
| 999 | if isequal(attr.key,'DirName') |
---|
| 1000 | cur_file=fullfile(attr.val,cur_file); |
---|
| 1001 | end |
---|
| 1002 | end |
---|
| 1003 | end |
---|
| 1004 | end |
---|
| 1005 | RootPath=fileparts(CurrentFile);%path to the current .xml file |
---|
| 1006 | cur_file=fullfile(RootPath,cur_file) |
---|
| 1007 | set(handles.CurrentAttributes,'UserData',cur_file)%will be searched by uvmat |
---|
| 1008 | [path,fil,ext]=fileparts(cur_file); |
---|
| 1009 | if ~exist(cur_file,'file') |
---|
[42] | 1010 | msgbox_uvmat('ERROR',['non-existent link file' cur_file]) % A FAIRE: propose to updtate the .xml file |
---|
[2] | 1011 | return |
---|
| 1012 | elseif isequal(ext,'.xml') |
---|
| 1013 | if ~isfield(Data,'UpFile') |
---|
| 1014 | Data.UpFile={CurrentFile}; |
---|
| 1015 | else |
---|
| 1016 | Data.UpFile=[{CurrentFile};Data.UpFile]; |
---|
| 1017 | end |
---|
| 1018 | set(heditxml,'UserData',Data) |
---|
| 1019 | set(handles.CurrentFile,'String',cur_file) |
---|
| 1020 | CurrentFile_Callback(handles.CurrentFile, [], handles) |
---|
| 1021 | else |
---|
| 1022 | if isequal(get(heditxml,'Tag'),'browser'); %if editxml has been called as a browser |
---|
| 1023 | set(heditxml,'Tag','idle')% signal for uvmat browser |
---|
| 1024 | else |
---|
| 1025 | uvmat({cur_file}); %open the link fiel with uvmat |
---|
| 1026 | end |
---|
| 1027 | return |
---|
| 1028 | end |
---|
| 1029 | end |
---|
| 1030 | %elseif isequal(attr.val,'dir') A FAIRE : check directory |
---|
| 1031 | %else A FAIRE: edit the element |
---|
| 1032 | end |
---|
| 1033 | end |
---|
| 1034 | attr_col=strvcat(attr_col,[attr.key ' = ' attr.val]); |
---|
| 1035 | end |
---|
| 1036 | set(handles.CurrentAttributes,'String',attr_col) |
---|
| 1037 | |
---|
| 1038 | %list subtree |
---|
| 1039 | if ~testsimple |
---|
| 1040 | list_element=[]; |
---|
| 1041 | % Data.CurrentUid=[Data.CurrentUid root_uid]%record new current uid |
---|
| 1042 | for iline=1:length(list_uid) |
---|
| 1043 | element=get(t,list_uid(iline)); |
---|
| 1044 | if isfield(element,'type')&isequal(element.type,'element') |
---|
| 1045 | list_element{iline,2}=element.name; |
---|
| 1046 | child_uid=children(t,list_uid(iline)); |
---|
| 1047 | subelem=get(t,child_uid); |
---|
| 1048 | if isfield(subelem,'type')& isfield(subelem,'value') & isequal(subelem.type,'chardata') |
---|
| 1049 | data_read=subelem.value; |
---|
| 1050 | list_element{iline,3}=['= ' data_read]; |
---|
| 1051 | end |
---|
| 1052 | if iscell(subelem)|(isfield(subelem,'type')&isequal(subelem.type,'element')) |
---|
| 1053 | list_element{iline,1}='+ ';%sign for subtree existence |
---|
| 1054 | else |
---|
| 1055 | list_element{iline,1}=' '; |
---|
| 1056 | end |
---|
| 1057 | nbattr=attributes(t,'length',list_uid(iline)); |
---|
| 1058 | if nbattr==1 |
---|
| 1059 | attr=attributes(t,'get',list_uid(iline)); |
---|
| 1060 | list_element{iline,4}=[attr.key '=']; |
---|
| 1061 | list_element{iline,5}=attr.val; |
---|
| 1062 | elseif nbattr>1 |
---|
| 1063 | for iattr=1:nbattr |
---|
| 1064 | attr=attributes(t,'get',list_uid(iline),iattr); |
---|
| 1065 | list_element{iline,2+2*iattr}=[attr.key '=']; |
---|
| 1066 | list_element{iline,3+2*iattr}=attr.val; |
---|
| 1067 | end |
---|
| 1068 | end |
---|
| 1069 | end |
---|
| 1070 | end |
---|
| 1071 | set(handles.list_element,'Value',1)%select the first line of list_element by default |
---|
| 1072 | set(handles.list_element,'String',cell2tab(list_element,' ') ) |
---|
| 1073 | list.uid=list_uid; |
---|
| 1074 | set(handles.list_element,'UserData',list) |
---|
| 1075 | end |
---|
| 1076 | %--------------------------------------------------------- |
---|
| 1077 | %------------------------------------- |
---|
| 1078 | %updates the interface |
---|
| 1079 | function update_ref_list(hh,xs_element,element,node,xs_subelem,subelem) |
---|
| 1080 | %----------------------------- |
---|
| 1081 | pref_col=''; |
---|
| 1082 | key_col=''; |
---|
| 1083 | equal_sign=''; |
---|
| 1084 | val_col=''; |
---|
| 1085 | for iline=1:length(subelem) |
---|
| 1086 | xsindex=subelem(iline).xsindex; |
---|
| 1087 | indexcur=subelem(iline).index; |
---|
| 1088 | subuid=subelem(iline).uid; |
---|
| 1089 | if isempty(subuid) |
---|
| 1090 | RefDataIn.uid(iline)=0; |
---|
| 1091 | else |
---|
| 1092 | RefDataIn.uid(iline)=subuid; |
---|
| 1093 | end |
---|
| 1094 | index(iline)=indexcur; |
---|
| 1095 | node(iline)=xs_subelem(xsindex).node; |
---|
| 1096 | % testmanual(iline)=subelem(iline).testmanual; |
---|
| 1097 | ikey=xs_subelem(xsindex).key; |
---|
| 1098 | if xs_subelem(xsindex).testsub |
---|
| 1099 | ival=[' + ' subelem(iline).val]; |
---|
| 1100 | else |
---|
| 1101 | ival=[' = ' subelem(iline).val]; |
---|
| 1102 | end |
---|
| 1103 | key_col=strvcat(key_col,ikey); |
---|
| 1104 | val_col=strvcat(val_col,ival); |
---|
| 1105 | end |
---|
| 1106 | RefDataIn.xs_uid=node; |
---|
| 1107 | list_element=[key_col val_col]; |
---|
| 1108 | siztext=size(list_element); |
---|
| 1109 | set(hh,'Value',[1:siztext(1)]) |
---|
| 1110 | set(hh,'String',list_element) |
---|
| 1111 | set(hh,'UserData',RefDataIn) |
---|
| 1112 | |
---|
| 1113 | % |
---|
| 1114 | % function RefFile_Callback(hObject, eventdata, handles) |
---|
| 1115 | % global t_ref xs |
---|
| 1116 | % t_ref=xmltree(get(hObject,'String'));%open the xml file fileinput |
---|
| 1117 | % heditxml=get(hObject,'parent'); |
---|
| 1118 | % DataIn=get(get(hObject,'parent'),'UserData'); |
---|
| 1119 | % % set(heditxml,'Units','pixel') |
---|
| 1120 | % figpos=get(heditxml,'Position') |
---|
| 1121 | % % title_element=get(handles.element_cur,'UserDataIn'); |
---|
| 1122 | % % xs_node=xsnode_index(1,ind); |
---|
| 1123 | % % index_chosen=xsnode_index(2,ind); |
---|
| 1124 | % if isfield(DataIn,'fig_ref')&ishandle(DataIn.fig_ref) |
---|
| 1125 | % figure(DataIn.fig_ref); |
---|
| 1126 | % else |
---|
| 1127 | % DataIn.fig_ref=figure; |
---|
| 1128 | % end |
---|
| 1129 | % set(DataIn.fig_ref,'Name',get(hObject,'String')) |
---|
| 1130 | % set(DataIn.fig_ref,'MenuBar','none') |
---|
| 1131 | % newfigpos=[figpos(1)+figpos(3) figpos(2)+0.4*figpos(4) 0.5*figpos(3) 0.3*figpos(4)]; |
---|
| 1132 | % set(DataIn.fig_ref,'Units','normalized') |
---|
| 1133 | % set(DataIn.fig_ref,'Position',newfigpos) |
---|
| 1134 | % DataIn.h_ref=uicontrol('Style','listbox', 'Max',2,'Units','pixel','Position', [0 0 newfigpos(3) newfigpos(4)], ... |
---|
| 1135 | % 'FontName','FixedWidth','Tag','listbox'); |
---|
| 1136 | % if isfield(DataIn,'xs_CurrentUid'); |
---|
| 1137 | % xs_CurrentUid=DataIn.xs_CurrentUid(end); |
---|
| 1138 | % else |
---|
| 1139 | % DataIn.xs_CurrentUid=find(xs,'/xs:schema/xs:element');%uid of the root element in the schema |
---|
| 1140 | % end |
---|
| 1141 | % [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_CurrentUid(end)); |
---|
| 1142 | % xs_element.key |
---|
| 1143 | % tag0=find(t_ref,['/' path '/' xs_element.key]); |
---|
| 1144 | % if length(tag0)>=1 |
---|
| 1145 | % CurrentRefNode=tag0(1);%chose the first occurence of the element |
---|
| 1146 | % else |
---|
| 1147 | % CurrentRefNode=0; |
---|
| 1148 | % end |
---|
| 1149 | % [ref_element,ref_subelem]=get_xml(t_ref,path,xs_element,CurrentRefNode,xs_subelem); |
---|
| 1150 | % update_ref_list(DataIn.h_ref,xs_element,ref_element,CurrentRefNode,xs_subelem,ref_subelem); |
---|
| 1151 | % siztext=size(get(DataIn.h_ref,'String')); |
---|
| 1152 | % set(DataIn.h_ref,'Value',[1:siztext(1)]); %select the whole list by default |
---|
| 1153 | % set(heditxml,'UserData',DataIn) |
---|
| 1154 | % set(handles.ref_data,'Value',siztext(1)); %select the whole list by default |
---|
| 1155 | % 'TESTimport' |
---|
| 1156 | % title_element=get(handles.element_cur,'UserDataIn') |
---|
| 1157 | % xs_node=title_element.xsnode;%uid of the element in the schema |
---|
| 1158 | % node=title_element.node; |
---|
| 1159 | % t=flush(t,node);%removes the corresponding subtree in t |
---|
| 1160 | % [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node);%scan the schema |
---|
| 1161 | % tag0=find(t_import,['/' path '/' xs_element.key]) |
---|
| 1162 | % if isempty(tag) |
---|
| 1163 | % errordlg(['element /' path '/' xs_element.key ' not found in' fileinput]) |
---|
| 1164 | % return |
---|
| 1165 | % end |
---|
| 1166 | % % [element_import,node_import]=get_xml(t_import,path,xs_element,1,xs_subelem);% read the corresponding xml data |
---|
| 1167 | % node2_import=children(t_import,tag0); |
---|
| 1168 | % % t_import=branch(t_import,node_import);% extract branch of the new file |
---|
| 1169 | % % %removes the corresponding subtree in t |
---|
| 1170 | % for inode=1:length(node2_import) |
---|
| 1171 | % struct=get(t_import,node2_import(inode)) |
---|
| 1172 | % if isfield(struct,'type') & isfield(struct,'name')%if the node is an elmeent type |
---|
| 1173 | % node3_import=children(t_import,node2_import(inode)) |
---|
| 1174 | % [t,newuid]=add(t,node,struct.type,struct.name); |
---|
| 1175 | % for inode2=1:length(node3_import) |
---|
| 1176 | % struct2=get(t_import,node3_import(inode2)) |
---|
| 1177 | % if isequal(struct2.type,'chardata') |
---|
| 1178 | % t=add(t,newuid,'chardata',struct2.value); |
---|
| 1179 | % end |
---|
| 1180 | % end |
---|
| 1181 | % end |
---|
| 1182 | % end |
---|
| 1183 | % --- Executes on button press in replicate. |
---|
| 1184 | function replicate_Callback(hObject, eventdata, handles) |
---|
| 1185 | global xs t |
---|
| 1186 | |
---|
| 1187 | export_list=get(handles.export_list,'String'); |
---|
| 1188 | export_val=get(handles.export_list,'UserData'); |
---|
| 1189 | heditxml=get(handles.replicate,'parent'); |
---|
| 1190 | Data=get(heditxml,'UserData') |
---|
| 1191 | |
---|
| 1192 | hdataview=findobj(allchild(0),'Name','dataview') |
---|
| 1193 | if isempty(hdataview) |
---|
| 1194 | hdataview=dataview; |
---|
| 1195 | return |
---|
| 1196 | end |
---|
| 1197 | hhdataview=guidata(hdataview); |
---|
| 1198 | CurrentPath=get(hhdataview.CurrentFile,'String'); |
---|
| 1199 | ListExperiments=get(hhdataview.ListExperiments,'String'); |
---|
| 1200 | Value=get(hhdataview.ListExperiments,'Value'); |
---|
| 1201 | if ~isequal(Value,1) |
---|
| 1202 | ListExperiments=ListExperiments(Value); |
---|
| 1203 | end |
---|
| 1204 | ListDevices=get(hhdataview.ListDevices,'String'); |
---|
| 1205 | Value=get(hhdataview.ListDevices,'Value'); |
---|
| 1206 | if ~isequal(Value,1) |
---|
| 1207 | ListDevices=ListDevices(Value); |
---|
| 1208 | end |
---|
| 1209 | ListRecords=get(hhdataview.ListRecords,'String'); |
---|
| 1210 | Value=get(hhdataview.ListRecords,'Value'); |
---|
| 1211 | if ~isequal(Value,1) |
---|
| 1212 | ListRecords=ListRecords(Value); |
---|
| 1213 | end |
---|
| 1214 | % uvmat('runplus_Callback',hObject,eventdata,handleshaxes) |
---|
| 1215 | [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords); |
---|
| 1216 | ListXml=get(hhdataview.ListXml,'String'); |
---|
| 1217 | Value=get(hhdataview.ListXml,'Value'); |
---|
| 1218 | if isequal(Value,1) |
---|
[42] | 1219 | msgbox_uvmat('ERROR','you need to select the xml files to edit') |
---|
[2] | 1220 | return |
---|
| 1221 | end |
---|
| 1222 | ListXml=ListXml(Value);%list of |
---|
| 1223 | for iexp=1:length(List.Experiment) |
---|
| 1224 | ExpName=List.Experiment{iexp}.name; |
---|
| 1225 | if isfield(List.Experiment{iexp},'Device') |
---|
| 1226 | for idevice=1:length(List.Experiment{iexp}.Device) |
---|
| 1227 | DeviceName=List.Experiment{iexp}.Device{idevice}.name; |
---|
| 1228 | if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile') |
---|
| 1229 | for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile) |
---|
| 1230 | FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}; |
---|
| 1231 | for ilistxml=1:length(ListXml) |
---|
| 1232 | if isequal(FileName,ListXml{ilistxml}) |
---|
| 1233 | xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName); |
---|
| 1234 | t_export=xmltree(xmlfullname); |
---|
| 1235 | rootelement=get(t_export,1,'name'); |
---|
| 1236 | uidlist=Data.CurrentUid; |
---|
| 1237 | if isequal(rootelement,get(t,1,'name')) |
---|
| 1238 | backupfile=xmlfullname; |
---|
| 1239 | testexist=2; |
---|
| 1240 | while testexist==2 |
---|
| 1241 | backupfile=[backupfile '~']; |
---|
| 1242 | testexist=exist(backupfile,'file'); |
---|
| 1243 | end |
---|
| 1244 | [success,message]=copyfile(xmlfullname,backupfile);%make backup |
---|
| 1245 | if ~isequal(success,1) |
---|
[42] | 1246 | msgbox_uvmat('ERROR',['Error in the backup of ' xmlfullname]) |
---|
[2] | 1247 | return |
---|
| 1248 | end |
---|
| 1249 | findstr=['/' rootelement]; |
---|
| 1250 | uid_export(1)=1; |
---|
| 1251 | % fill the root elements if absent |
---|
| 1252 | for index=2:length(uidlist) |
---|
| 1253 | name_t=get(t,uidlist(index),'name') |
---|
| 1254 | findstr=[findstr '/' name_t] |
---|
| 1255 | uid=find(t_export,findstr) |
---|
| 1256 | if isempty(uid) |
---|
| 1257 | [t_export,uid_export(index)]=add(t_export,uid_export(index-1),'element',name_t); |
---|
| 1258 | else |
---|
| 1259 | uid_export(index)=uid; |
---|
| 1260 | end |
---|
| 1261 | end |
---|
| 1262 | % chardata...... |
---|
| 1263 | end |
---|
| 1264 | break |
---|
| 1265 | end |
---|
| 1266 | end |
---|
| 1267 | % [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest); |
---|
| 1268 | % if test |
---|
| 1269 | % [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated'] |
---|
| 1270 | % end |
---|
| 1271 | end |
---|
| 1272 | elseif isfield(List.Experiment{iexp}.Device{idevice},'Record') |
---|
| 1273 | for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record) |
---|
| 1274 | RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name; |
---|
| 1275 | if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile') |
---|
| 1276 | for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile) |
---|
| 1277 | FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}; |
---|
| 1278 | for ilistxml=1:length(ListXml) |
---|
| 1279 | if isequal(FileName,ListXml{ilistxml}) |
---|
| 1280 | xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName) |
---|
| 1281 | break |
---|
| 1282 | end |
---|
| 1283 | end |
---|
| 1284 | % [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest); |
---|
| 1285 | % if test |
---|
| 1286 | % [FileName ' , Heading updated'] |
---|
| 1287 | % end |
---|
| 1288 | end |
---|
| 1289 | end |
---|
| 1290 | end |
---|
| 1291 | end |
---|
| 1292 | end |
---|
| 1293 | end |
---|
| 1294 | end |
---|
| 1295 | return |
---|
| 1296 | %%%%%%%%%%% A REVOIR |
---|
| 1297 | % Copier la liste des elements selectionnés dans dataview |
---|
| 1298 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 1299 | %ANCIEN: |
---|
| 1300 | heditxml=get(hObject,'parent'); |
---|
| 1301 | DataIn=get(heditxml,'UserData'); |
---|
| 1302 | if ~isfield(DataIn,'h_ref') |
---|
| 1303 | DataIn.h_ref=[]; |
---|
| 1304 | end |
---|
| 1305 | if ~ishandle(DataIn.h_ref) |
---|
| 1306 | errordlg('no source file opened for import') |
---|
| 1307 | return |
---|
| 1308 | end |
---|
| 1309 | %create the current root element if needed |
---|
| 1310 | LengthElement=length(DataIn.CurrentUid); |
---|
| 1311 | FilledUid=find(DataIn.CurrentUid~=0); |
---|
| 1312 | LengthFilled=FilledUid(end); |
---|
| 1313 | for irank=LengthFilled+1:LengthElement |
---|
| 1314 | attrib=attributes(xs,'get',DataIn.xs_CurrentUid(irank),1); |
---|
| 1315 | [t,DataIn.CurrentUid(irank)]=add(t,DataIn.CurrentUid(irank-1),'element',attrib.val); |
---|
| 1316 | end |
---|
| 1317 | |
---|
| 1318 | %copy list of subelements |
---|
| 1319 | RefDataIn=get(DataIn.h_ref,'UserData'); |
---|
| 1320 | list=get(handles.list_element,'UserData');%=,[node;index] |
---|
| 1321 | for ilist=get(DataIn.h_ref,'Value') |
---|
| 1322 | node_content=get(xs,RefDataIn.xs_uid(ilist)); |
---|
| 1323 | if ~isempty(node_content) & isfield(node_content,'attributes') |
---|
| 1324 | attrib=node_content.attributes; |
---|
| 1325 | for iattr=1:length(attrib) |
---|
| 1326 | struct=attrib{iattr}; |
---|
| 1327 | if isequal(struct.key,'name') |
---|
| 1328 | key=struct.val; % read element key name |
---|
| 1329 | end |
---|
| 1330 | end |
---|
| 1331 | end |
---|
| 1332 | value=''; |
---|
| 1333 | if ~isequal(RefDataIn.uid(ilist),0) |
---|
| 1334 | child_uid=children(t_ref,RefDataIn.uid(ilist)); |
---|
| 1335 | if isequal(length(child_uid),1) |
---|
| 1336 | content=get(t_ref,child_uid); |
---|
| 1337 | if isfield(content,'type') &isfield(content,'value')& isequal(content.type,'chardata') |
---|
| 1338 | value=content.value; |
---|
| 1339 | end |
---|
| 1340 | end |
---|
| 1341 | end |
---|
| 1342 | t=set_element(t,DataIn.CurrentUid(end),list.uid(ilist),key,value); |
---|
| 1343 | end |
---|
| 1344 | set(heditxml,'UserData',DataIn) |
---|
| 1345 | %update the current listing |
---|
| 1346 | [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,DataIn.xs_CurrentUid(end)); |
---|
| 1347 | [element,subelem]=get_xml(t,path,xs_element,DataIn.CurrentUid(end),xs_subelem); |
---|
| 1348 | update_list(handles,path,xs_element,element,DataIn.CurrentUid(end),xs_subelem,subelem); |
---|
| 1349 | % t=set_xml(t,xs_DataIn,subelem) |
---|
| 1350 | %edit list of subelments: |
---|
| 1351 | |
---|
| 1352 | %A REVOIR |
---|
| 1353 | % xsnode_index=get(handles.list_element,'UserDataIn') |
---|
| 1354 | % xs_node=xsnode_index(1,ind); |
---|
| 1355 | % RefDataIn=get(handles.ref_data,'UserDataIn'); |
---|
| 1356 | % subelem=RefDataIn.subelem; |
---|
| 1357 | % xsnode_index=get(handles.list_element,'UserDataIn');%data on the xs_nodes of the subelements |
---|
| 1358 | % ref_list=get(handles.ref_data,'Value');%selected indices in the list of reference subelements |
---|
| 1359 | % xs_node=xsnode_index(1,ref_list);%xs_nodes of the selected subelements |
---|
| 1360 | % % index_chosen=xsnode_index(2,ref_list);% indices in the list of occurence for a subelement |
---|
| 1361 | % % for ilist=ref_list |
---|
| 1362 | % ilist=1; |
---|
| 1363 | % while icontinue |
---|
| 1364 | % 'TESTCOPY' |
---|
| 1365 | % [nodeup,path,xs_element,xs_subelem]=scan_schema(xs,xs_node(ilist)) |
---|
| 1366 | % xs_subelem.key |
---|
| 1367 | % tsub=subelem(ilist).tsub |
---|
| 1368 | % xsnode_index(2,ilist) |
---|
| 1369 | % [ref_elem,ref_node,ref_subelem]=get_xml(tsub,'',xs_element,1,xs_subelem) |
---|
| 1370 | % ref_subelem.val |
---|
| 1371 | % testedit= ~isfield(element.attrup,'source') | isequal(element.attrup.source,'manual') %| element vide |
---|
| 1372 | % |
---|
| 1373 | % |
---|
| 1374 | % icontinue=0 |
---|
| 1375 | % end |
---|
| 1376 | % function [element,node,subelem]=get_xml(t,path,xs_element,node,xs_subelem) |
---|
| 1377 | % element.attr_key='';%default |
---|
| 1378 | % element.attr_val='';%default |
---|
| 1379 | % element.val=''; |
---|
| 1380 | % % element.type=''; |
---|
| 1381 | % % element.testmanual=testmanual %inheritates the input manual editing flag by default |
---|
| 1382 | % subelem=[]; %default |
---|
| 1383 | % attrup=[]; |
---|
| 1384 | % % node=[]; |
---|
| 1385 | % |
---|
| 1386 | % % %find the element properties in the xml file |
---|
| 1387 | % if node >= 1 |
---|
| 1388 | % elem_struct=get(t,node); |
---|
| 1389 | % if ~xs_element.subtest |
---|
| 1390 | % elem_contents=get(t,elem_struct.contents); |
---|
| 1391 | % if isempty(elem_contents) |
---|
| 1392 | % element.val=[]; |
---|
| 1393 | % else |
---|
| 1394 | % element.val=elem_contents.value |
---|
| 1395 | % end |
---|
| 1396 | % end |
---|
| 1397 | % if isfield(elem_struct,'attributes') |
---|
| 1398 | % elem_attr=elem_struct.attributes; |
---|
| 1399 | % for iattr=1:length(elem_attr) |
---|
| 1400 | % element.attr_key{iattr}=elem_attr{iattr}.key ; |
---|
| 1401 | % element.attr_val{iattr}=elem_attr{iattr}.val; |
---|
| 1402 | % % attrup=setfield(attrup,elem_attr{iattr}.key,elem_attr{iattr}.val); |
---|
| 1403 | % breakdetect=find(elem_attr{iattr}.key=='/'| elem_attr{iattr}.key==':'| elem_attr{iattr}.key=='.');% find '/' |
---|
| 1404 | % if isempty(breakdetect) |
---|
| 1405 | % % comline=['attrup.' elem_attr{iattr}.key '=' elem_attr{iattr}.val ';'] |
---|
| 1406 | % eval(['attrup.' elem_attr{iattr}.key '=''' elem_attr{iattr}.val ''';']) |
---|
| 1407 | % end |
---|
| 1408 | % end |
---|
| 1409 | % end |
---|
| 1410 | % end |
---|
| 1411 | % %get the parent node attributes |
---|
| 1412 | % up=1 |
---|
| 1413 | % if node>0 |
---|
| 1414 | % nodeup=node; |
---|
| 1415 | % while up==1; |
---|
| 1416 | % nodeup=get(t,nodeup,'parent');%move up to the parent in the tree |
---|
| 1417 | % if isempty(nodeup) |
---|
| 1418 | % up=0; |
---|
| 1419 | % else |
---|
| 1420 | % nodeup_content=get(t,nodeup); |
---|
| 1421 | % attrib=nodeup_content.attributes; |
---|
| 1422 | % for iattr=1:length(attrib) |
---|
| 1423 | % key=attrib{iattr}.key; |
---|
| 1424 | % breakdetect=find(key=='/'| key==':'| key=='.');% find '/' |
---|
| 1425 | % if ~isfield(attrup,key) & isempty(breakdetect) |
---|
| 1426 | % eval(['attrup.' key '=''' attrib{iattr}.val ''';']) |
---|
| 1427 | % end |
---|
| 1428 | % end |
---|
| 1429 | % end |
---|
| 1430 | % end |
---|
| 1431 | % element.attrup=attrup; |
---|
| 1432 | % end |
---|
| 1433 | % %find the subelement properties in the xml file |
---|
| 1434 | % if xs_element.subtest |
---|
| 1435 | % iline=0; |
---|
| 1436 | % for k=1:length(xs_subelem)%node2: list of subelements in the sub-sequence |
---|
| 1437 | % % attr=attributes(xs,'get',node2(i),1);% |
---|
| 1438 | % % element=attr.val;%name of the element |
---|
| 1439 | % tag=find(t,['/' path '/' xs_element.key '/' xs_subelem(k).key]);%look for the corresponding element node in the .xml tree |
---|
| 1440 | % struct_element=get(t,tag);%get the content of the element |
---|
| 1441 | % if isempty(struct_element) |
---|
| 1442 | % iline=iline+1; |
---|
| 1443 | % subelem(iline).xsindex=k; |
---|
| 1444 | % subelem(iline).index=0; |
---|
| 1445 | % % subelem(iline).testmanual=element.testmanual;% inheritates the manual editing flag by default |
---|
| 1446 | % if isequal(xs_subelem(k).minOccurs,0) |
---|
| 1447 | % subelem(iline).val='[]';%element value not mandatory in the schema |
---|
| 1448 | % else |
---|
| 1449 | % subelem(iline).val='[MISSING]';%element value mandatory in the schema |
---|
| 1450 | % end |
---|
| 1451 | % % subelem(iline).attrup=attrup; %inheritated attributes |
---|
| 1452 | % elseif isequal(length(struct_element),1) |
---|
| 1453 | % contents=get(t,struct_element.contents); |
---|
| 1454 | % iline=iline+1; |
---|
| 1455 | % subelem(iline).xsindex=k; |
---|
| 1456 | % subelem(iline).index=1; |
---|
| 1457 | % % subelem(iline).testmanual=element.testmanual;% |
---|
| 1458 | % if isfield(contents,'value') & ~isempty(contents.value) |
---|
| 1459 | % subelem(iline).val=contents.value; |
---|
| 1460 | % elseif xs_subelem(k).testsub |
---|
| 1461 | % subelem(iline).val=''; |
---|
| 1462 | % elseif isequal(xs_subelem(k).minOccurs,0) |
---|
| 1463 | % subelem(iline).val='[]';%element value not mandatory in the schema |
---|
| 1464 | % else |
---|
| 1465 | % subelem(iline).val='[MISSING]';%element value mandatory in the schema |
---|
| 1466 | % end |
---|
| 1467 | % % subelem(iline).attrup=attrup; %inheritated attributes |
---|
| 1468 | % if isfield(struct_element,'attributes') |
---|
| 1469 | % element_attr=struct_element.attributes; |
---|
| 1470 | % attr_display=[]; |
---|
| 1471 | % for iattr=1:length(element_attr) |
---|
| 1472 | % % attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 1473 | % subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 1474 | % % subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val); |
---|
| 1475 | % end |
---|
| 1476 | % end |
---|
| 1477 | % else%case of a multiple element |
---|
| 1478 | % for subindex=1:length(struct_element) |
---|
| 1479 | % contents=get(t,struct_element{subindex}.contents); |
---|
| 1480 | % iline=iline+1; |
---|
| 1481 | % subelem(iline).index=subindex;%index of the element |
---|
| 1482 | % subelem(iline).xsindex=k; |
---|
| 1483 | % % subelem(iline).testmanual=element.testmanual;% |
---|
| 1484 | % if isfield(contents,'value')& ~isempty(contents.value) |
---|
| 1485 | % subelem(iline).val=contents.value; |
---|
| 1486 | % elseif xs_subelem(k).testsub |
---|
| 1487 | % subelem(iline).val=''; |
---|
| 1488 | % else |
---|
| 1489 | % subelem(iline).val='[]'; |
---|
| 1490 | % end |
---|
| 1491 | % % subelem(iline).attrup=attrup; %inheritated attributes |
---|
| 1492 | % if isfield(struct_element{subindex},'attributes') |
---|
| 1493 | % element_attr=struct_element{subindex}.attributes; |
---|
| 1494 | % attr_display=[]; |
---|
| 1495 | % for iattr=1:length(element_attr) |
---|
| 1496 | % % attr_display{iline}=[attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 1497 | % subelem(iline).val=[subelem(iline).val attr_display ' , ' element_attr{iattr}.key ' = ' element_attr{iattr}.val]; |
---|
| 1498 | % % subelem(iline).attrup=setfield(subelem(iline).attrup,element_attr{iattr}.key,element_attr{iattr}.val); |
---|
| 1499 | % end |
---|
| 1500 | % end |
---|
| 1501 | % end |
---|
| 1502 | % end |
---|
| 1503 | % end |
---|
| 1504 | % end |
---|
| 1505 | |
---|
| 1506 | |
---|
| 1507 | % --- Executes on button press in HELP. |
---|
| 1508 | function HELP_Callback(hObject, eventdata, handles) |
---|
| 1509 | path_to_uvmat=which ('uvmat')% check the path of uvmat |
---|
| 1510 | pathelp=fileparts(path_to_uvmat); |
---|
| 1511 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
| 1512 | if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
| 1513 | else |
---|
| 1514 | web([helpfile '#editxml']) |
---|
| 1515 | end |
---|
| 1516 | |
---|
| 1517 | |
---|
| 1518 | % --- Executes on button press in Export. |
---|
| 1519 | function Export_Callback(hObject, eventdata, handles) |
---|
| 1520 | val=get(handles.Export,'Value'); |
---|
| 1521 | if val |
---|
| 1522 | set(handles.Export,'BackgroundColor',[0 1 0]) |
---|
| 1523 | set(handles.export_list,'Visible','on') |
---|
| 1524 | set(handles.replicate,'Visible','on') |
---|
| 1525 | h_dataview=findobj(allchild(0),'name',dataview'); |
---|
| 1526 | if isempty(h_dataview) |
---|
| 1527 | % CurrentFile=get(handles.CurrentFile,'String'); |
---|
| 1528 | dataview; |
---|
| 1529 | end |
---|
| 1530 | else |
---|
| 1531 | set(handles.Export,'BackgroundColor',[0.7 0.7 0.7]) |
---|
| 1532 | set(handles.export_list,'Visible','off') |
---|
| 1533 | set(handles.replicate,'Visible','off') |
---|
| 1534 | end |
---|
| 1535 | |
---|
| 1536 | |
---|
| 1537 | % --- Executes on button press in pushbutton9. |
---|
| 1538 | function pushbutton9_Callback(hObject, eventdata, handles) |
---|
| 1539 | % hObject handle to pushbutton9 (see GCBO) |
---|
| 1540 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 1541 | % handles structure with handles and user data (see GUIDATA) |
---|
| 1542 | |
---|
| 1543 | |
---|