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 xml_getattribs
Home > sltoolbox > xmlkits > xml_getattribs.m

xml_getattribs

PURPOSE ^

XML_GETATTRIBS Constructs an attribte struct from an XML element

SYNOPSIS ^

function A = xml_getattribs(xelem, varargin)

DESCRIPTION ^

XML_GETATTRIBS Constructs an attribte struct from an XML element

 $ Syntax $
   - A = xml_getattribs(xelem)
   - A = xml_getattribs(xelem, ...)

 $ Arguments $
   - xelem:          the XML element
   - A:              the struct of attributes
                     - the field name represents the attribute name
                     - the field value (string) is the attribute value

 $ Description $
   - A = xml_getattribs(xelem) constructs the struct representing
     the attributes in the XML element xelem, with the attribute names
     stored in the struct fields, while the attribute values stored in the
     struct values in terms of char string.
   
   - A = xml_getattribs(xelem, ...) constructs the
     attribute struct with following properties:
       - 'exclude': a cell array of excluded attribute names, default = {}
       - 'select':  a cell array of selected attribute names, default = {}
       - 'forceexist': whether the fields must exist for select, 
                       default = true;

 $ Remarks $
   - If select is specified, then exclude will be ignored.
   - All selected attributes should exist.

 $ History $
   - Created by Dahua Lin on Jul 23rd, 2006

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
  • readfile READFILE Reads the dataset from DSDML file
  • edl_readexpdefs EDL_READEXPDEFS Reads in an experiment definition from XML file
  • edl_readexpdefs_old EDL_READEXPDEFS Reads in experiment definition XML file
  • edl_readprops EDL_READPROPS Reads properties from a property table XML file

SOURCE CODE ^

0001 function A = xml_getattribs(xelem, varargin)
0002 %XML_GETATTRIBS Constructs an attribte struct from an XML element
0003 %
0004 % $ Syntax $
0005 %   - A = xml_getattribs(xelem)
0006 %   - A = xml_getattribs(xelem, ...)
0007 %
0008 % $ Arguments $
0009 %   - xelem:          the XML element
0010 %   - A:              the struct of attributes
0011 %                     - the field name represents the attribute name
0012 %                     - the field value (string) is the attribute value
0013 %
0014 % $ Description $
0015 %   - A = xml_getattribs(xelem) constructs the struct representing
0016 %     the attributes in the XML element xelem, with the attribute names
0017 %     stored in the struct fields, while the attribute values stored in the
0018 %     struct values in terms of char string.
0019 %
0020 %   - A = xml_getattribs(xelem, ...) constructs the
0021 %     attribute struct with following properties:
0022 %       - 'exclude': a cell array of excluded attribute names, default = {}
0023 %       - 'select':  a cell array of selected attribute names, default = {}
0024 %       - 'forceexist': whether the fields must exist for select,
0025 %                       default = true;
0026 %
0027 % $ Remarks $
0028 %   - If select is specified, then exclude will be ignored.
0029 %   - All selected attributes should exist.
0030 %
0031 % $ History $
0032 %   - Created by Dahua Lin on Jul 23rd, 2006
0033 %
0034 
0035 
0036 %% Parse and verify input arguments
0037 
0038 opts.select = {};
0039 opts.exclude = {};
0040 opts.forceexist = true;
0041 opts = slparseprops(opts, varargin{:});
0042 
0043 
0044 %% Construction
0045 
0046 A = [];
0047 
0048 
0049 
0050 if isempty(opts.select) && isempty(opts.exclude) % full construction
0051 
0052     attrMap = xelem.getAttributes;
0053     n = attrMap.getLength;
0054 
0055     for i = 1 : n
0056         
0057         attr = attrMap.item(i-1);
0058         attrname = char(attr.getName);
0059         attrval = char(attr.getValue);
0060         
0061         A.(attrname) = attrval;
0062         
0063     end
0064     
0065     
0066 elseif ~isempty(opts.select)    % selection
0067     
0068     n = length(opts.select);
0069     for i = 1 : n
0070         
0071         attrname = opts.select{i};
0072         if xelem.hasAttribute(attrname)
0073             A.(attrname) = char(xelem.getAttribute(attrname));
0074         else
0075             if opts.forceexist
0076                 error('sltoolbox:xmlerror', ...
0077                     'The selected attribute %s does not exist', attrname);
0078             end
0079         end
0080         
0081     end    
0082     
0083 else                            % has excluding
0084     
0085     attrMap = xelem.getAttributes;
0086     n = attrMap.getLength;
0087 
0088     for i = 1 : n
0089         
0090         attr = attrMap.item(i-1);
0091         attrname = char(attr.getName);
0092         
0093         if ~ismember(attrname, opts.exclude)            
0094             attrval = char(attr.getValue);
0095             A.(attrname) = attrval;        
0096         end
0097         
0098     end
0099         
0100 end
0101 
0102 
0103 
0104

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

Contact us at files@mathworks.com