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_readprops
Home > sltoolbox > ExpDL > edl_readprops.m

edl_readprops

PURPOSE ^

EDL_READPROPS Reads properties from a property table XML file

SYNOPSIS ^

function S = edl_readprops(filename, nodetag)

DESCRIPTION ^

EDL_READPROPS Reads properties from a property table XML file

 $ Syntax $
   - S = edl_readprops(filename, nodetag)

 $ Arguments $
   - filename:     the filename of the XML file describing the properties
   - nodetag:      the tag name of each child node of the document node
   - S:            the struct array of read document
                   - 'tag':  the document node tag
                   - 'attribs': the document node attributes
                   - the struct array using nodetag as fieldname

 $ Description $
   - S = edl_readprops(filename, nodetag) reads a table of properties from 
     a property table XML file.

 $ 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:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • xml_getattribs XML_GETATTRIBS Constructs an attribte struct from an XML element
This function is called by:

SOURCE CODE ^

0001 function S = edl_readprops(filename, nodetag)
0002 %EDL_READPROPS Reads properties from a property table XML file
0003 %
0004 % $ Syntax $
0005 %   - S = edl_readprops(filename, nodetag)
0006 %
0007 % $ Arguments $
0008 %   - filename:     the filename of the XML file describing the properties
0009 %   - nodetag:      the tag name of each child node of the document node
0010 %   - S:            the struct array of read document
0011 %                   - 'tag':  the document node tag
0012 %                   - 'attribs': the document node attributes
0013 %                   - the struct array using nodetag as fieldname
0014 %
0015 % $ Description $
0016 %   - S = edl_readprops(filename, nodetag) reads a table of properties from
0017 %     a property table XML file.
0018 %
0019 % $ History $
0020 %   - Created by Dahua Lin, on Aug 10th, 2006
0021 %   - Modified by Dahua Lin, on Aug 13rd, 2006
0022 %       - adds support of document header attribute
0023 %       - changes the structure of the result
0024 %       - adds the selection of node tag
0025 %
0026 
0027 %% Read file
0028 
0029 if nargin < 2
0030     raise_lackinput('edl_readprops', 2);
0031 end
0032     
0033 xdoc = xmlread(filename);
0034 docelem = xdoc.getDocumentElement;
0035 
0036 %% Read header
0037 
0038 S.tag = char(docelem.getTagName);
0039 S.attribs = xml_getattribs(docelem);
0040 
0041 
0042 %% Read properties
0043 
0044 propElemList = docelem.getElementsByTagName(nodetag);
0045 n = propElemList.getLength;
0046 
0047 if n > 0
0048     % pre-allocation
0049     % (this can remarkably accelerates the construction of large struct array)
0050     attrMap = propElemList.item(0).getAttributes;
0051     firstattr = attrMap.item(0);
0052     firstname = char(firstattr.getName);
0053     entries = struct(firstname, cell(n, 1));
0054 
0055     for i = 1 : n
0056 
0057         curentry = propElemList.item(i-1);
0058         attrMap = curentry.getAttributes;
0059         na = attrMap.getLength;
0060 
0061         for j = 1 : na
0062             attr = attrMap.item(j-1);
0063             attrname = char(attr.getName);
0064             attrval = char(attr.getValue);
0065             entries(i).(attrname) = attrval;
0066         end
0067 
0068     end
0069 else    
0070     entries = [];
0071 end
0072 
0073 S.(nodetag) = entries;
0074 
0075 
0076

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

Contact us at files@mathworks.com