source: trunk/src/@xmltree/delete.m @ 964

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

xmltree updated

File size: 1.2 KB
Line 
1function tree = delete(tree,uid)
2% XMLTREE/DELETE Delete (delete a subtree given its UID)
3%
4% tree      - XMLTree object
5% uid       - array of UID's of subtrees to be deleted
6%__________________________________________________________________________
7%
8% Delete a subtree given its UID
9% The tree parameter must be in input AND in output
10%__________________________________________________________________________
11% Copyright (C) 2002-2011  http://www.artefact.tk/
12
13% Guillaume Flandin
14% $Id: delete.m 4460 2011-09-05 14:52:16Z guillaume $
15
16%error(nargchk(2,2,nargin));
17
18uid = uid(:);
19for i=1:length(uid)
20    if uid(i)==1
21        warning('[XMLTree] Cannot delete root element.');
22    else
23        p = tree.tree{uid(i)}.parent;
24        tree = sub_delete(tree,uid(i));
25        tree.tree{p}.contents(find(tree.tree{p}.contents==uid(i))) = [];
26    end
27end
28
29%==========================================================================
30function tree = sub_delete(tree,uid)
31    if isfield(tree.tree{uid},'contents')
32        for i=1:length(tree.tree{uid}.contents)
33            tree = sub_delete(tree,tree.tree{uid}.contents(i));
34        end
35    end
36    tree.tree{uid} = struct('type','deleted');
Note: See TracBrowser for help on using the repository browser.