-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathflush.m
42 lines (37 loc) · 1.39 KB
/
flush.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
function tree = flush(tree,uid)
% XMLTREE/FLUSH Flush (Clear a subtree given its UID)
%
% tree - XMLTree object
% uid - array of UID's of subtrees to be cleared
% Default is root
%_______________________________________________________________________
%
% Clear a subtree given its UID (remove all the leaves of the tree)
% The tree parameter must be in input AND in output
%_______________________________________________________________________
% Copyright (C) 2002-2008 http://www.artefact.tk/
% Guillaume Flandin <guillaume@artefact.tk>
% $Id: flush.m 1460 2008-04-21 17:43:18Z guillaume $
error(nargchk(1,2,nargin));
if nargin == 1,
uid = root(tree);
end
uid = uid(:);
for i=1:length(uid)
tree = sub_flush(tree,uid(i));
end
%=======================================================================
function tree = sub_flush(tree,uid)
if isfield(tree.tree{uid},'contents')
% contents is parsed in reverse order because each child is
% deleted and the contents vector is then eventually reduced
for i=length(tree.tree{uid}.contents):-1:1
tree = sub_flush(tree,tree.tree{uid}.contents(i));
end
end
if strcmp(tree.tree{uid}.type,'chardata') ||...
strcmp(tree.tree{uid}.type,'pi') ||...
strcmp(tree.tree{uid}.type,'cdata') ||...
strcmp(tree.tree{uid}.type,'comment')
tree = delete(tree,uid);
end