-
Notifications
You must be signed in to change notification settings - Fork 1
/
omxmlread.m
55 lines (49 loc) · 1.17 KB
/
omxmlread.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% Class omxmlread
% Read OpenModelica xml file
% Author: Milos Petrasinovic <[email protected]>
% PR-DC, Republic of Serbia
% ---------------
classdef omxmlread
properties (Access = private)
data;
ids;
end
methods
function obj = omxmlread(file)
path = mfilename('fullpath');
path = path(1:end-length(mfilename));
addpath([path '\xml_parser']);
obj.data = xml_parser(file);
obj.ids = cell2mat({obj.data(:).id});
end
function val = getLength(obj)
val = length(obj.ids);
end
function obj = getElementsByTagName(obj, tag, id)
if(nargin > 2)
ids = obj.data(id).children;
else
ids = obj.ids;
end
i = strcmp(tag, {obj.data(ids).tag});
if(any(i))
obj.ids = ids(i);
else
obj.ids = [];
end
end
function val = item(obj,i)
val = obj.data(obj.ids(i));
end
function val = getAttribute(obj, i, attribute)
id = obj.ids(i);
[i,j] = ismember(attribute, obj.data(id).attribute_keys);
if(i)
val = obj.data(id).attributes(j).value;
else
val = [];
end
end
end
end