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