source: trunk/src/uvmat_doc/FUNCTIONS_DOC/struct2xml.html @ 37

Last change on this file since 37 was 37, checked in by sommeria, 14 years ago

create_grid.fig ,
uvmat_doc and all the included files added

File size: 9.5 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2                "http://www.w3.org/TR/REC-html40/loose.dtd">
3<html>
4<head>
5  <title>Description of struct2xml</title>
6  <meta name="keywords" content="struct2xml">
7  <meta name="description" content="'struct2xml': transform a matlab structure to a xml tree.">
8  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
10  <meta name="robots" content="index, follow">
11  <link type="text/css" rel="stylesheet" href="../m2html.css">
12</head>
13<body>
14<a name="_top"></a>
15<div><a href="../index.html">Home</a> &gt;  <a href="index.html">.</a> &gt; struct2xml.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for .&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->
19
20<h1>struct2xml
21</h1>
22
23<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
24<div class="box"><strong>'struct2xml': transform a matlab structure to a xml tree.</strong></div>
25
26<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
27<div class="box"><strong>function t=struct2xml(Object,t,root_uid) </strong></div>
28
29<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
30<div class="fragment"><pre class="comment">'struct2xml': transform a matlab structure to a xml tree.
31--------------------------------------------------------------
32 each field with char string or num vector is transformed into a corresponding  xml element
33 each field with a matrix containing n lines is transformed into a xml element repeated n times
34 WARNING: PROBLEM WITH HIERARCHICAL structures
35%%%%%%%%%%%%%%%%%%%%%%
36 OUTPUT:
37 t: xmltree reproducing the structure of Object
38 type 'save(t)' to visualize the xml text and save(filename,t) to save it in a file
39
40 INPUT:
41  Object: matlab structure, possibly hierarchical
42  t: optional input xml tree in which a new branch needs to be appended
43  root_uid: optional uid of the xml element under which the new subtree must be appended</pre></div>
44
45<!-- crossreference -->
46<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
47This function calls:
48<ul style="list-style-image:url(../matlabicon.gif)">
49<li><a href="struct2xml.html" class="code" title="function t=struct2xml(Object,t,root_uid)">struct2xml</a>      'struct2xml': transform a matlab structure to a xml tree.</li></ul>
50This function is called by:
51<ul style="list-style-image:url(../matlabicon.gif)">
52<li><a href="civ_3D.html" class="code" title="function varargout = civ_3D(varargin)">civ_3D</a> 'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume</li><li><a href="dataview.html" class="code" title="function varargout = dataview(varargin)">dataview</a>       TEST 'dataview': function for scanning directories in a campaign (TEST)</li><li><a href="geometry_calib.html" class="code" title="function varargout = geometry_calib(varargin)">geometry_calib</a>     'geometry_calib': performs geometric calibration from a set of reference points</li><li><a href="probe_calib.html" class="code" title="function varargout = probe_calib(varargin)">probe_calib</a>      'probe_calib': performs geometric calibration from a set of reference points</li><li><a href="series.html" class="code" title="function varargout = series(varargin)">series</a>        'series': master function associated to the GUI series.m for analysis field series</li><li><a href="set_object.html" class="code" title="function varargout = set_object(varargin)">set_object</a>      'set_object': GUI to edit a projection object</li><li><a href="struct2xml.html" class="code" title="function t=struct2xml(Object,t,root_uid)">struct2xml</a>    'struct2xml': transform a matlab structure to a xml tree.</li></ul>
53<!-- crossreference -->
54
55<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
56<ul style="list-style-image:url(../matlabicon.gif)">
57<li><a href="#_sub1" class="code">function t=add_element(t,uid,key,val)</a></li></ul>
58<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
59<div class="fragment"><pre>0001 <span class="comment">%'struct2xml': transform a matlab structure to a xml tree.</span>
600002 <span class="comment">%--------------------------------------------------------------</span>
610003 <span class="comment">% each field with char string or num vector is transformed into a corresponding  xml element</span>
620004 <span class="comment">% each field with a matrix containing n lines is transformed into a xml element repeated n times</span>
630005 <span class="comment">% WARNING: PROBLEM WITH HIERARCHICAL structures</span>
640006 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%</span>
650007 <span class="comment">% OUTPUT:</span>
660008 <span class="comment">% t: xmltree reproducing the structure of Object</span>
670009 <span class="comment">% type 'save(t)' to visualize the xml text and save(filename,t) to save it in a file</span>
680010 <span class="comment">%</span>
690011 <span class="comment">% INPUT:</span>
700012 <span class="comment">%  Object: matlab structure, possibly hierarchical</span>
710013 <span class="comment">%  t: optional input xml tree in which a new branch needs to be appended</span>
720014 <span class="comment">%  root_uid: optional uid of the xml element under which the new subtree must be appended</span>
730015
740016 <a name="_sub0" href="#_subfunctions" class="code">function t=struct2xml(Object,t,root_uid)</a>
750017 <span class="comment">% if ~exist('rootname','var')</span>
760018 <span class="comment">%     rootname='Object';</span>
770019 <span class="comment">% end</span>
780020
790021 <span class="keyword">if</span> ~exist(<span class="string">'t'</span>,<span class="string">'var'</span>)
800022     t=xmltree;
810023 <span class="keyword">end</span>
820024 <span class="keyword">if</span> ~exist(<span class="string">'root_uid'</span>,<span class="string">'var'</span>)
830025     root_uid=1;
840026 <span class="keyword">end</span>
850027 <span class="comment">% if exist('rootname','var')%name the root element with the struct root</span>
860028 <span class="comment">%     if ischar(rootname)</span>
870029 <span class="comment">%         t=set(t,1,'name',rootname);</span>
880030 <span class="comment">%     end</span>
890031 <span class="comment">%     %Faire cas rootname= tree</span>
900032 <span class="comment">%   % eval(['Object=Object.' fieldnames{1}]); %get the substructure</span>
910033 <span class="comment">% end</span>
920034
930035     fieldnames=fields(Object);
940036     <span class="keyword">for</span> ilist=1:length(fieldnames)
950037        eval([<span class="string">'val=Object.'</span> fieldnames{ilist} <span class="string">';'</span>])
960038        <span class="keyword">if</span> isstruct(val)
970039           [t,uid]=add(t,root_uid,<span class="string">'element'</span>,fieldnames{ilist});
980040           fieldnames_sub=fields(val);
990041           <span class="keyword">for</span> ilist_sub=1:length(fieldnames_sub)
1000042               <span class="keyword">if</span> isstruct(fieldnames_sub{ilist_sub})
1010043                     t=<a href="struct2xml.html" class="code" title="function t=struct2xml(Object,t,root_uid)">struct2xml</a>(fieldnames_sub{ilist_sub},t,uid);
1020044                     save(t)
1030045               <span class="keyword">else</span>
1040046                   eval([<span class="string">'val_sub=val.'</span> fieldnames_sub{ilist_sub} <span class="string">';'</span>])
1050047                   t=<a href="#_sub1" class="code" title="subfunction t=add_element(t,uid,key,val)">add_element</a>(t,uid,fieldnames_sub{ilist_sub},val_sub);
1060048               <span class="keyword">end</span>
1070049           <span class="keyword">end</span>
1080050        <span class="keyword">else</span>
1090051            t=<a href="#_sub1" class="code" title="subfunction t=add_element(t,uid,key,val)">add_element</a>(t,root_uid,fieldnames{ilist},val);
1100052        <span class="keyword">end</span>
1110053     <span class="keyword">end</span>
1120054
1130055     
1140056 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
1150057 <a name="_sub1" href="#_subfunctions" class="code">function t=add_element(t,uid,key,val)</a>
1160058  <span class="keyword">if</span> ischar(val)
1170059      [t,new_uid]=add(t,uid,<span class="string">'element'</span>,key);
1180060      [t]=add(t,new_uid,<span class="string">'chardata'</span>,val);
1190061  <span class="keyword">elseif</span> isnumeric(val)
1200062        siz=size(val);
1210063        <span class="keyword">if</span> length(siz)&lt;=2 <span class="comment">%do not translate matrices with more than 2 indices</span>
1220064            <span class="keyword">for</span> iline=1:siz(1)
1230065                 val_str=num2str(val(iline,:));
1240066                 [t,new_uid]=add(t,uid,<span class="string">'element'</span>,key);
1250067                 <span class="keyword">if</span> siz(1)&gt;1
1260068                     t = attributes(t,<span class="string">'add'</span>,new_uid,<span class="string">'i'</span>,num2str(iline));
1270069                 <span class="keyword">end</span>
1280070                 [t]=add(t,new_uid,<span class="string">'chardata'</span>,val_str);
1290071            <span class="keyword">end</span>
1300072        <span class="keyword">end</span>
1310073  <span class="keyword">end</span></pre></div>
132<hr><address>Generated on Fri 13-Nov-2009 11:17:03 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
133</body>
134</html>
Note: See TracBrowser for help on using the repository browser.