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

Last change on this file since 723 was 723, checked in by sommeria, 10 years ago

xmltree and toolbox_calib added to svn

File size: 1.2 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% @(#)flush.m                  Guillaume Flandin               02/04/10
13
14error(nargchk(1,2,nargin));
15
16if nargin == 1,
17        uid = root(tree);
18end
19
20uid = uid(:);
21for i=1:length(uid)
22         tree = sub_flush(tree,uid(i));
23end
24
25%=======================================================================
26function tree = sub_flush(tree,uid)
27        if isfield(tree.tree{uid},'contents')
28                % contents is parsed in reverse order because each child is
29                % deleted and the contents vector is then eventually reduced
30                for i=length(tree.tree{uid}.contents):-1:1
31                        tree = sub_flush(tree,tree.tree{uid}.contents(i));
32                end
33        end
34        if strcmp(tree.tree{uid}.type,'chardata') |...
35                strcmp(tree.tree{uid}.type,'pi') |...
36                strcmp(tree.tree{uid}.type,'cdata') |...
37                strcmp(tree.tree{uid}.type,'comment')
38                tree = delete(tree,uid);
39        end
Note: See TracBrowser for help on using the repository browser.