source: trunk/src/editxml.m @ 35

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