Changeset 925 for trunk/src/@xmltree/branch.m
- Timestamp:
- Feb 17, 2016, 12:52:48 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/branch.m
r821 r925 6 6 % uid - UID of the root element of the subtree 7 7 % subtree - XMLTree object (a subtree from tree) 8 %_______________________________________________________________________ 8 %__________________________________________________________________________ 9 9 % 10 10 % Return a subtree from a tree. 11 %_______________________________________________________________________ 12 % @(#)branch.m Guillaume Flandin 02/04/1711 %__________________________________________________________________________ 12 % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 13 14 error(nargchk(2,2,nargin)); 14 % Guillaume Flandin 15 % $Id: branch.m 4460 2011-09-05 14:52:16Z guillaume $ 15 16 16 if uid > length(tree) | ... 17 prod(size(uid))~=1 | ... 17 18 %error(nargchk(2,2,nargin)); 19 20 if uid > length(tree) || ... 21 numel(uid)~=1 || ... 18 22 ~strcmp(tree.tree{uid}.type,'element') 19 23 error('[XMLTree] Invalid UID.'); 20 24 end 21 25 … … 28 32 29 33 for i=1:length(child) 30 31 32 34 l = length(subtree); 35 subtree = sub_branch(tree,subtree,child(i),root(subtree)); 36 subtree.tree{root(subtree)}.contents = [subtree.tree{root(subtree)}.contents l+1]; 33 37 end 34 38 35 %======================================================================= 39 %========================================================================== 36 40 function tree = sub_branch(t,tree,uid,p) 37 41 38 39 40 41 42 43 44 45 46 47 48 49 50 51 42 l = length(tree); 43 tree.tree{l+1} = t.tree{uid}; 44 tree.tree{l+1}.uid = l + 1; 45 tree.tree{l+1}.parent = p; 46 tree.tree{l+1}.contents = []; 47 if isfield(t.tree{uid},'contents') 48 contents = get(t,uid,'contents'); 49 m = length(tree); 50 for i=1:length(contents) 51 tree.tree{l+1}.contents = [tree.tree{l+1}.contents m+1]; 52 tree = sub_branch(t,tree,contents(i),l+1); 53 m = length(tree); 54 end 55 end
Note: See TracChangeset
for help on using the changeset viewer.