Changeset 925 for trunk/src/@xmltree/flush.m
- Timestamp:
- Feb 17, 2016, 12:52:48 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/flush.m
r723 r925 5 5 % uid - array of UID's of subtrees to be cleared 6 6 % Default is root 7 %_______________________________________________________________________ 7 %__________________________________________________________________________ 8 8 % 9 9 % Clear a subtree given its UID (remove all the leaves of the tree) 10 10 % The tree parameter must be in input AND in output 11 %_______________________________________________________________________ 12 % @(#)flush.m Guillaume Flandin 02/04/1011 %__________________________________________________________________________ 12 % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 13 14 error(nargchk(1,2,nargin)); 14 % Guillaume Flandin 15 % $Id: flush.m 4460 2011-09-05 14:52:16Z guillaume $ 16 17 18 %error(nargchk(1,2,nargin)); 15 19 16 20 if nargin == 1, 17 21 uid = root(tree); 18 22 end 19 23 20 24 uid = uid(:); 21 25 for i=1:length(uid) 22 26 tree = sub_flush(tree,uid(i)); 23 27 end 24 28 25 %======================================================================= 29 %========================================================================== 26 30 function tree = sub_flush(tree,uid) 27 28 29 30 31 32 33 34 if strcmp(tree.tree{uid}.type,'chardata')|...35 strcmp(tree.tree{uid}.type,'pi')|...36 strcmp(tree.tree{uid}.type,'cdata')|...37 38 39 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 TracChangeset
for help on using the changeset viewer.