-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdelete.m
36 lines (32 loc) · 1.17 KB
/
delete.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
function tree = delete(tree,uid)
% XMLTREE/DELETE Delete (delete a subtree given its UID)
%
% tree - XMLTree object
% uid - array of UID's of subtrees to be deleted
%_______________________________________________________________________
%
% Delete a subtree given its UID
% The tree parameter must be in input AND in output
%_______________________________________________________________________
% Copyright (C) 2002-2008 http://www.artefact.tk/
% Guillaume Flandin <guillaume@artefact.tk>
% $Id: delete.m 1460 2008-04-21 17:43:18Z guillaume $
error(nargchk(2,2,nargin));
uid = uid(:);
for i=1:length(uid)
if uid(i)==1
warning('[XMLTree] Cannot delete root element.');
else
p = tree.tree{uid(i)}.parent;
tree = sub_delete(tree,uid(i));
tree.tree{p}.contents(find(tree.tree{p}.contents==uid(i))) = [];
end
end
%=======================================================================
function tree = sub_delete(tree,uid)
if isfield(tree.tree{uid},'contents')
for i=1:length(tree.tree{uid}.contents)
tree = sub_delete(tree,tree.tree{uid}.contents(i));
end
end
tree.tree{uid} = struct('type','deleted');