[37] | 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 © 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> > <a href="index.html">.</a> > struct2xml.m</div> |
---|
| 16 | |
---|
| 17 | <!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> |
---|
| 18 | <td align="right"><a href="index.html">Index for . <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> |
---|
| 47 | This 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> |
---|
| 50 | This 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> |
---|
| 60 | 0002 <span class="comment">%--------------------------------------------------------------</span> |
---|
| 61 | 0003 <span class="comment">% each field with char string or num vector is transformed into a corresponding xml element</span> |
---|
| 62 | 0004 <span class="comment">% each field with a matrix containing n lines is transformed into a xml element repeated n times</span> |
---|
| 63 | 0005 <span class="comment">% WARNING: PROBLEM WITH HIERARCHICAL structures</span> |
---|
| 64 | 0006 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
| 65 | 0007 <span class="comment">% OUTPUT:</span> |
---|
| 66 | 0008 <span class="comment">% t: xmltree reproducing the structure of Object</span> |
---|
| 67 | 0009 <span class="comment">% type 'save(t)' to visualize the xml text and save(filename,t) to save it in a file</span> |
---|
| 68 | 0010 <span class="comment">%</span> |
---|
| 69 | 0011 <span class="comment">% INPUT:</span> |
---|
| 70 | 0012 <span class="comment">% Object: matlab structure, possibly hierarchical</span> |
---|
| 71 | 0013 <span class="comment">% t: optional input xml tree in which a new branch needs to be appended</span> |
---|
| 72 | 0014 <span class="comment">% root_uid: optional uid of the xml element under which the new subtree must be appended</span> |
---|
| 73 | 0015 |
---|
| 74 | 0016 <a name="_sub0" href="#_subfunctions" class="code">function t=struct2xml(Object,t,root_uid)</a> |
---|
| 75 | 0017 <span class="comment">% if ~exist('rootname','var')</span> |
---|
| 76 | 0018 <span class="comment">% rootname='Object';</span> |
---|
| 77 | 0019 <span class="comment">% end</span> |
---|
| 78 | 0020 |
---|
| 79 | 0021 <span class="keyword">if</span> ~exist(<span class="string">'t'</span>,<span class="string">'var'</span>) |
---|
| 80 | 0022 t=xmltree; |
---|
| 81 | 0023 <span class="keyword">end</span> |
---|
| 82 | 0024 <span class="keyword">if</span> ~exist(<span class="string">'root_uid'</span>,<span class="string">'var'</span>) |
---|
| 83 | 0025 root_uid=1; |
---|
| 84 | 0026 <span class="keyword">end</span> |
---|
| 85 | 0027 <span class="comment">% if exist('rootname','var')%name the root element with the struct root</span> |
---|
| 86 | 0028 <span class="comment">% if ischar(rootname)</span> |
---|
| 87 | 0029 <span class="comment">% t=set(t,1,'name',rootname);</span> |
---|
| 88 | 0030 <span class="comment">% end</span> |
---|
| 89 | 0031 <span class="comment">% %Faire cas rootname= tree</span> |
---|
| 90 | 0032 <span class="comment">% % eval(['Object=Object.' fieldnames{1}]); %get the substructure</span> |
---|
| 91 | 0033 <span class="comment">% end</span> |
---|
| 92 | 0034 |
---|
| 93 | 0035 fieldnames=fields(Object); |
---|
| 94 | 0036 <span class="keyword">for</span> ilist=1:length(fieldnames) |
---|
| 95 | 0037 eval([<span class="string">'val=Object.'</span> fieldnames{ilist} <span class="string">';'</span>]) |
---|
| 96 | 0038 <span class="keyword">if</span> isstruct(val) |
---|
| 97 | 0039 [t,uid]=add(t,root_uid,<span class="string">'element'</span>,fieldnames{ilist}); |
---|
| 98 | 0040 fieldnames_sub=fields(val); |
---|
| 99 | 0041 <span class="keyword">for</span> ilist_sub=1:length(fieldnames_sub) |
---|
| 100 | 0042 <span class="keyword">if</span> isstruct(fieldnames_sub{ilist_sub}) |
---|
| 101 | 0043 t=<a href="struct2xml.html" class="code" title="function t=struct2xml(Object,t,root_uid)">struct2xml</a>(fieldnames_sub{ilist_sub},t,uid); |
---|
| 102 | 0044 save(t) |
---|
| 103 | 0045 <span class="keyword">else</span> |
---|
| 104 | 0046 eval([<span class="string">'val_sub=val.'</span> fieldnames_sub{ilist_sub} <span class="string">';'</span>]) |
---|
| 105 | 0047 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); |
---|
| 106 | 0048 <span class="keyword">end</span> |
---|
| 107 | 0049 <span class="keyword">end</span> |
---|
| 108 | 0050 <span class="keyword">else</span> |
---|
| 109 | 0051 t=<a href="#_sub1" class="code" title="subfunction t=add_element(t,uid,key,val)">add_element</a>(t,root_uid,fieldnames{ilist},val); |
---|
| 110 | 0052 <span class="keyword">end</span> |
---|
| 111 | 0053 <span class="keyword">end</span> |
---|
| 112 | 0054 |
---|
| 113 | 0055 |
---|
| 114 | 0056 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
| 115 | 0057 <a name="_sub1" href="#_subfunctions" class="code">function t=add_element(t,uid,key,val)</a> |
---|
| 116 | 0058 <span class="keyword">if</span> ischar(val) |
---|
| 117 | 0059 [t,new_uid]=add(t,uid,<span class="string">'element'</span>,key); |
---|
| 118 | 0060 [t]=add(t,new_uid,<span class="string">'chardata'</span>,val); |
---|
| 119 | 0061 <span class="keyword">elseif</span> isnumeric(val) |
---|
| 120 | 0062 siz=size(val); |
---|
| 121 | 0063 <span class="keyword">if</span> length(siz)<=2 <span class="comment">%do not translate matrices with more than 2 indices</span> |
---|
| 122 | 0064 <span class="keyword">for</span> iline=1:siz(1) |
---|
| 123 | 0065 val_str=num2str(val(iline,:)); |
---|
| 124 | 0066 [t,new_uid]=add(t,uid,<span class="string">'element'</span>,key); |
---|
| 125 | 0067 <span class="keyword">if</span> siz(1)>1 |
---|
| 126 | 0068 t = attributes(t,<span class="string">'add'</span>,new_uid,<span class="string">'i'</span>,num2str(iline)); |
---|
| 127 | 0069 <span class="keyword">end</span> |
---|
| 128 | 0070 [t]=add(t,new_uid,<span class="string">'chardata'</span>,val_str); |
---|
| 129 | 0071 <span class="keyword">end</span> |
---|
| 130 | 0072 <span class="keyword">end</span> |
---|
| 131 | 0073 <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> © 2003</address> |
---|
| 133 | </body> |
---|
| 134 | </html> |
---|