0001 function DS = readfile(DS, filename)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 xdoc = xmlread(filename);
0023 docelem = getDocumentElement(xdoc);
0024
0025
0026 classname = class(DS);
0027 S = struct(DS);
0028
0029 S.version = char(docelem.getAttribute('version'));
0030 S.name = char(docelem.getAttribute('name'));
0031 S.unittype = char(docelem.getAttribute('unit'));
0032 S.format = char(docelem.getAttribute('format'));
0033 if (docelem.hasAttribute('author'))
0034 S.author = char(docelem.getAttribute('author'));
0035 else
0036 S.author = [];
0037 end
0038 if (docelem.hasAttribute('description'))
0039 S.description = char(docelem.getAttribute('description'));
0040 else
0041 S.description = [];
0042 end
0043 S.attribs = xml_getattribs(docelem, 'exclude', {...
0044 'version', ...
0045 'name', ...
0046 'unit', ...
0047 'format', ...
0048 'author', ...
0049 'description' ...
0050 'attribs'});
0051
0052 if ~ismember(S.unittype, {'Sample', 'SampleGroup'})
0053 error('dsdml:invalidutype', ...
0054 'Invalid unit type %s', S.unittype);
0055 end
0056
0057
0058
0059 S.units = [];
0060 unitnodes = docelem.getElementsByTagName(S.unittype);
0061 numnodes = unitnodes.getLength;
0062
0063 ucells = cell(numnodes, 1);
0064
0065 switch(S.unittype)
0066 case 'Sample'
0067 for i = 1 : numnodes
0068 ucells{i} = CreateSample(unitnodes.item(i-1));
0069 end
0070
0071 case 'SampleGroup'
0072 for i = 1 : numnodes
0073 ucells{i} = CreateSampleGroup(unitnodes.item(i-1));
0074 end
0075 end
0076 S.units = [ucells{:}];
0077 S.units = S.units(:);
0078
0079 DS = class(S, classname);
0080
0081
0082
0083
0084
0085 function S = CreateSample(node)
0086
0087 S.class_id = str2double(char(node.getAttribute('class_id')));
0088 S.filename = [];
0089 if node.hasAttribute('filename')
0090 S.filename = char(node.getAttribute('filename'));
0091 end
0092 S.attribs = xml_getattribs(node, 'exclude', {'class_id', 'filename', 'attribs'});
0093
0094
0095 function S = CreateSampleGroup(node)
0096
0097 S.class_id = str2double(char(node.getAttribute('class_id')));
0098 S.attribs = xml_getattribs(node, 'exclude', {'class_id', 'attribs'});
0099 S.samples = [];
0100
0101 samplenodes = node.getElementsByTagName('Sample');
0102 numsamples = samplenodes.getLength;
0103 scells = cell(numsamples, 1);
0104 for i = 1 : numsamples
0105 scells{i} = CreateSample(samplenodes.item(i-1));
0106 end
0107
0108 S.samples = [scells{:}];
0109 S.samples = S.samples(:);
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120