Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of edl_writeprops
Home > sltoolbox > ExpDL > edl_writeprops.m

edl_writeprops

PURPOSE ^

EDL_WRITEPROPS Writes the property table to XML file

SYNOPSIS ^

function edl_writeprops(doctag, attribs, nodeTag, props, filename)

DESCRIPTION ^

EDL_WRITEPROPS Writes the property table to XML file

 $ Syntax $
   - edl_writeprops(doctag, attribs, nodeTag, props, filename)

 $ Arguments $
   - doctag:       the tag name of document node
   - attribs:      the header attributes
   - nodeTag:      the tag name of child nodes
   - props:        the struct array of all properties
   - filename:     the name of the XML file to be written to

 $ Description $
   - edl_writeprops(doctag, attribs, nodeTag, props, filename) writes 
     a table of properties to an XML property table file, with the
     header attributes.

 $ Remarks $
   - For numeric values, they will be converted to string using num2str.

 $ History $
   - Created by Dahua Lin, on Aug 10th, 2006
   - Modified by Dahua Lin, on Aug 13rd, 2006
       - adds support of document header attribute
       - changes the structure of the result
       - adds the selection of node tag

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slfilepart SLFILEPARTS Extracts a specified part of a file path string
  • slmkdir SLMKDIR Makes a directory if it does not exist
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • xml_addattribs XML_ADDATTRIBS Adds attributes to an element
This function is called by:

SOURCE CODE ^

0001 function edl_writeprops(doctag, attribs, nodeTag, props, filename)
0002 %EDL_WRITEPROPS Writes the property table to XML file
0003 %
0004 % $ Syntax $
0005 %   - edl_writeprops(doctag, attribs, nodeTag, props, filename)
0006 %
0007 % $ Arguments $
0008 %   - doctag:       the tag name of document node
0009 %   - attribs:      the header attributes
0010 %   - nodeTag:      the tag name of child nodes
0011 %   - props:        the struct array of all properties
0012 %   - filename:     the name of the XML file to be written to
0013 %
0014 % $ Description $
0015 %   - edl_writeprops(doctag, attribs, nodeTag, props, filename) writes
0016 %     a table of properties to an XML property table file, with the
0017 %     header attributes.
0018 %
0019 % $ Remarks $
0020 %   - For numeric values, they will be converted to string using num2str.
0021 %
0022 % $ History $
0023 %   - Created by Dahua Lin, on Aug 10th, 2006
0024 %   - Modified by Dahua Lin, on Aug 13rd, 2006
0025 %       - adds support of document header attribute
0026 %       - changes the structure of the result
0027 %       - adds the selection of node tag
0028 
0029 import com.mathworks.xml.*;
0030 
0031 %% parse and verify input arguments
0032 
0033 if nargin < 5
0034     raise_lackinput('edl_writeprops', 5);
0035 end
0036 
0037 if ~isstruct(props)
0038     error('sltoolbox:invalidarg', ...
0039         'props should be a struct array');
0040 end
0041 
0042 %% Write file
0043 
0044 % create document
0045 
0046 xdoc = XMLUtils.createDocument(doctag);
0047 xdoc.setVersion('1.0');
0048 xdoc.setEncoding('UTF-8');
0049 
0050 docelem = xdoc.getDocumentElement;
0051 
0052 
0053 % write header
0054 docelem = xml_addattribs(docelem, attribs);
0055 
0056 
0057 % add elements
0058 
0059 n = numel(props);
0060 fns = fieldnames(props);
0061 cf = length(fns);
0062 
0063 for i = 1 : n
0064     
0065     propelem = xdoc.createElement(nodeTag);
0066     cur = props(i);
0067     
0068     for j = 1 : cf
0069         fn = fns{j};
0070         val = cur.(fn);
0071         if isnumeric(val)
0072             val = num2str(val);
0073         end
0074         propelem.setAttribute(fn, val);
0075     end
0076     
0077     docelem.appendChild(propelem);
0078     
0079 end
0080 
0081 % write to file
0082 filedir = slfilepart(filename, 'parent');
0083 slmkdir(filedir);
0084 xmlwrite(filename, xdoc);
0085 
0086     
0087     
0088

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com