source: trunk/src/@xmltree/branch.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.4 KB
Line 
1function subtree = branch(tree,uid)
2% XMLTREE/BRANCH Branch Method
3% FORMAT uid = parent(tree,uid)
4%
5% tree    - XMLTree object
6% uid     - UID of the root element of the subtree
7% subtree - XMLTree object (a subtree from tree)
8%_______________________________________________________________________
9%
10% Return a subtree from a tree.
11%_______________________________________________________________________
12% @(#)branch.m                  Guillaume Flandin              02/04/17
13
14error(nargchk(2,2,nargin));
15
16if uid > length(tree) | ...
17   prod(size(uid))~=1 | ...
18   ~strcmp(tree.tree{uid}.type,'element')
19        error('[XMLTree] Invalid UID.');
20end
21
22subtree = xmltree;
23subtree = set(subtree,root(subtree),'name',tree.tree{uid}.name);
24
25child = children(tree,uid);
26
27for i=1:length(child)
28        l = length(subtree);
29        subtree = sub_branch(tree,subtree,child(i),root(subtree));
30        subtree.tree{root(subtree)}.contents = [subtree.tree{root(subtree)}.contents l+1];
31end
32
33%=======================================================================
34function tree = sub_branch(t,tree,uid,p)
35
36        l = length(tree);
37        tree.tree{l+1} = t.tree{uid};
38        tree.tree{l+1}.uid = l + 1;
39        tree.tree{l+1}.parent = p;
40        tree.tree{l+1}.contents = [];
41        if isfield(t.tree{uid},'contents')
42                contents = get(t,uid,'contents');
43                m = length(tree);
44                for i=1:length(contents)
45                        tree.tree{l+1}.contents = [tree.tree{l+1}.contents m+1];
46                        tree = sub_branch(t,tree,contents(i),l+1);
47                        m = length(tree);
48                end
49        end
Note: See TracBrowser for help on using the repository browser.