comparison m-toolbox/classes/+utils/@xml/attachStructToDom.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1
2 function collectedHist = attachStructToDom(objs, dom, parent, collectedHist)
3
4 % Store the structure shape in the parent node
5 parent.setAttribute('structShape', sprintf('%dx%d', size(objs)));
6 parent.setAttribute('type', class(objs));
7
8 if isempty(objs)
9
10 % Create structure node
11 structNode = dom.createElement('struct');
12 structNode.setAttribute('structShape', sprintf('%dx%d', size(objs)));
13 structNode.setAttribute('shape', sprintf('%dx%d', size(objs)));
14 structNode.setAttribute('type', 'empty-struct');
15
16 % Add to parent node
17 parent.appendChild(structNode);
18
19 else
20
21 for oo = 1:numel(objs)
22 obj = objs(oo);
23 fnames = fieldnames(obj);
24
25 % Create structure node
26 structNode = dom.createElement('struct');
27 structNode.setAttribute('structShape', sprintf('%dx%d', size(objs)));
28
29 for ff=1:numel(fnames)
30 val = obj.(fnames{ff});
31
32 % Create structure node
33 fieldnameNode = dom.createElement(fnames{ff});
34 fieldnameNode.setAttribute('shape', sprintf('%dx%d', size(val)));
35 fieldnameNode.setAttribute('type', class(val));
36
37 if isnumeric(val)
38
39 utils.xml.attachNumberToDom(val, dom, fieldnameNode);
40
41 elseif islogical(val)
42 content = dom.createTextNode(utils.xml.mat2str(val));
43 fieldnameNode.appendChild(content);
44
45 elseif isa(val, 'sym')
46 utils.xml.attachSymToDom(val, dom, fieldnameNode);
47
48 elseif ischar(val)
49 utils.xml.attachCharToDom(val, dom, fieldnameNode);
50
51 elseif isa(val, 'ltpda_obj')
52 collectedHist = val.attachToDom(dom, fieldnameNode, collectedHist);
53
54 elseif iscell(val)
55 collectedHist = utils.xml.attachCellToDom(val, dom, fieldnameNode, collectedHist);
56
57 elseif isstruct(val)
58 collectedHist = utils.xml.attachStructToDom(val, dom, fieldnameNode, collectedHist);
59
60 elseif isjava(val)
61 if strcmp(class(val), 'sun.util.calendar.ZoneInfo')
62 content = dom.createTextNode(char(val.getID));
63 fieldnameNode.appendChild(content);
64 else
65 error('### Unknown JAVA class. Can not attach the java class %s to DOM.', class(val));
66 end
67
68 else
69 error('!!! Please code me up for the class [%s]', class(val));
70 end
71
72 % Add fieldname node to structure node
73 structNode.appendChild(fieldnameNode);
74
75 end % ff=1:numel(fnames)
76
77 % Add structure node to parent
78 parent.appendChild(structNode);
79
80 end % oo = 1:numel(objs)
81
82 end
83
84 end