source: trunk/src/@xmltree/flush.m @ 1162

Last change on this file since 1162 was 925, checked in by sommeria, 9 years ago

xmltree updated

File size: 1.4 KB
Line 
1function tree = flush(tree,uid)
2% XMLTREE/FLUSH Flush (Clear a subtree given its UID)
3%
4% tree      - XMLTree object
5% uid       - array of UID's of subtrees to be cleared
6%             Default is root
7%__________________________________________________________________________
8%
9% Clear a subtree given its UID (remove all the leaves of the tree)
10% The tree parameter must be in input AND in output
11%__________________________________________________________________________
12% Copyright (C) 2002-2011  http://www.artefact.tk/
13
14% Guillaume Flandin
15% $Id: flush.m 4460 2011-09-05 14:52:16Z guillaume $
16
17
18%error(nargchk(1,2,nargin));
19
20if nargin == 1,
21    uid = root(tree);
22end
23
24uid = uid(:);
25for i=1:length(uid)
26     tree = sub_flush(tree,uid(i));
27end
28
29%==========================================================================
30function tree = sub_flush(tree,uid)
31    if isfield(tree.tree{uid},'contents')
32        % contents is parsed in reverse order because each child is
33        % deleted and the contents vector is then eventually reduced
34        for i=length(tree.tree{uid}.contents):-1:1
35            tree = sub_flush(tree,tree.tree{uid}.contents(i));
36        end
37    end
38    if strcmp(tree.tree{uid}.type,'chardata') ||...
39        strcmp(tree.tree{uid}.type,'pi') ||...
40        strcmp(tree.tree{uid}.type,'cdata') ||...
41        strcmp(tree.tree{uid}.type,'comment')
42        tree = delete(tree,uid);
43    end
Note: See TracBrowser for help on using the repository browser.