Home > classes > @param > xmladd.m

xmladd

PURPOSE ^

XMLADD add a parameter object to the given node of the input XML

SYNOPSIS ^

function xml = xmladd(ps, xml, nodename, node)

DESCRIPTION ^

 XMLADD add a parameter object to the given node of the input XML
 DOM object.

 M Hewitson 14-02-07

 $Id: xmladd.html,v 1.6 2008/02/12 12:17:58 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function xml = xmladd(ps, xml, nodename, node)
0002 
0003 % XMLADD add a parameter object to the given node of the input XML
0004 % DOM object.
0005 %
0006 % M Hewitson 14-02-07
0007 %
0008 % $Id: xmladd.html,v 1.6 2008/02/12 12:17:58 hewitson Exp $
0009 %
0010 
0011 el = xml.docNode.createElement(nodename);
0012 
0013 for j=1:length(ps)
0014   p = ps(j);
0015   % Now add object
0016   elc = xml.docNode.createElement('param');
0017 
0018   %% Add AO name
0019   elcc = xml.docNode.createElement('name');
0020   elcc.appendChild(xml.docNode.createTextNode(p.name));
0021   elc.appendChild(elcc);
0022 
0023   % add Created
0024   xml = xmladd(p.created, xml, 'created', elc);
0025 
0026   % add version
0027   elcc = xml.docNode.createElement('version');
0028   elcc.appendChild(xml.docNode.createTextNode(p.version));
0029   elc.appendChild(elcc);
0030 
0031   % add key
0032   elcc = xml.docNode.createElement('key');
0033   elcc.appendChild(xml.docNode.createTextNode(p.key));
0034   elc.appendChild(elcc);
0035 
0036   % add value: char
0037   if ischar(p.val)
0038     elcc = xml.docNode.createElement('value');
0039     elcc.appendChild(xml.docNode.createTextNode(p.val));
0040     elc.appendChild(elcc);
0041 
0042   % add value: numeric
0043   elseif isnumeric(p.val)
0044     elcc = xml.docNode.createElement('value');
0045     elcc.appendChild(xml.docNode.createTextNode(ltpda_mat2str(p.val)));
0046     elc.appendChild(elcc);
0047 
0048   % add value: logical
0049   elseif islogical(p.val)
0050     elcc = xml.docNode.createElement('value');
0051     if (p.val == true)
0052       elcc.appendChild(xml.docNode.createTextNode('logical value: true'));
0053     else
0054       elcc.appendChild(xml.docNode.createTextNode('logical value: false'));
0055     end
0056     elc.appendChild(elcc);
0057 
0058   % add value: cell array of char
0059   elseif iscell(p.val)
0060     if isempty(p.val)
0061         elcc = xml.docNode.createElement('value');
0062         elcc.appendChild(xml.docNode.createTextNode(''));
0063         elc.appendChild(elcc);
0064     else
0065       if ischar(p.val{1})
0066         elcc = xml.docNode.createElement('value');
0067         str = 'CELL:';
0068         for jj=1:length(p.val)
0069           str = [str ' ' p.val{jj}];
0070         end
0071         elcc.appendChild(xml.docNode.createTextNode(str));
0072         elc.appendChild(elcc);
0073       else
0074         error('### The value of a parameter can only contain a cell array of character');
0075       end
0076     end
0077   % add value: object
0078   else
0079     xml = xmladd(p.val, xml, 'value', elc);
0080   end
0081 
0082   el.appendChild(elc);
0083 end
0084 
0085 node.appendChild(el);
0086 
0087 
0088 
0089 % END

Generated on Tue 12-Feb-2008 13:12:45 by m2html © 2003