Changeset 925 for trunk/src/@xmltree/attributes.m
- Timestamp:
- Feb 17, 2016, 12:52:48 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/attributes.m
r821 r925 13 13 % 14 14 % tree = attributes(tree,'set',uid,n,key,val) 15 % 16 % 17 % 18 % 19 %_______________________________________________________________________ 15 % attr = attributes(tree,'get',uid[,n]) 16 % tree = attributes(tree,'add',uid,key,val) 17 % tree = attributes(tree,'del',uid[,n]) 18 % l = attributes(tree,'length',uid) 19 %__________________________________________________________________________ 20 20 % 21 21 % Handle attributes of an element node. 22 22 % The tree parameter must be in input AND in output for 'set', 'add' and 23 23 % 'del' methods. 24 %_______________________________________________________________________ 25 % @(#)attributes.m Guillaume Flandin 02/04/0524 %__________________________________________________________________________ 25 % Copyright (C) 2002-2011 http://www.artefact.tk/ 26 26 27 error(nargchk(3,6,nargin)); 27 % Guillaume Flandin 28 % $Id: attributes.m 4460 2011-09-05 14:52:16Z guillaume $ 29 30 31 %error(nargchk(3,6,nargin)); 32 28 33 tree = varargin{1}; 29 if ~ischar(varargin{2}) | ...34 if ~ischar(varargin{2}) || ... 30 35 ~any(strcmp(varargin{2},{'set','get','add','del','length'})) 31 36 error('[XMLTree] Unknown method.'); 32 37 end 33 38 uid = varargin{3}; 34 if ~isa(uid,'double') | any(uid>length(tree))| any(uid<1)35 39 if ~isa(uid,'double') || any(uid>length(tree)) || any(uid<1) 40 error('[XMLTree] UID must be a positive integer scalar.'); 36 41 end 37 42 38 43 if ~strcmp(tree.tree{uid}.type,'element') 39 44 error('[XMLTree] This node has no attributes.'); 40 45 end 41 46 42 47 switch varargin{2} 43 44 45 if ~isa(varargin{4},'double')| ...46 any(varargin{4}>length(tree.tree{uid}.attributes))| ...47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 elseif ~isa(varargin{4},'double')| ...65 any(varargin{4}>length(tree.tree{uid}.attributes))| ...66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 if ~isa(varargin{4},'double')| ...97 any(varargin{4}>length(tree.tree{uid}.attributes))| ...98 99 100 101 102 103 104 105 106 107 108 109 110 111 48 case 'set' 49 %error(nargchk(6,6,nargin)); 50 if ~isa(varargin{4},'double') || ... 51 any(varargin{4}>length(tree.tree{uid}.attributes)) || ... 52 any(varargin{4}<1) 53 error('[XMLTree] Invalid attribute indice.'); 54 end 55 ind = varargin{4}; 56 tree.tree{uid}.attributes{ind} = struct('key',varargin{5},'val',varargin{6}); 57 varargout{1} = tree; 58 case 'get' 59 %error(nargchk(3,4,nargin)); 60 if nargin == 4 61 if ischar(varargin{4}) 62 for i=1:length(tree.tree{uid}.attributes) 63 if strcmp(varargin{4},tree.tree{uid}.attributes{i}.key) 64 varargout{1} = tree.tree{uid}.attributes{i}.val; 65 return; 66 end 67 end 68 varargout{1} = []; 69 elseif ~isa(varargin{4},'double') || ... 70 any(varargin{4}>length(tree.tree{uid}.attributes)) || ... 71 any(varargin{4}<1) 72 error('[XMLTree] Invalid attribute indice.'); 73 else 74 if length(varargin{4}) == 1 75 varargout{1} = tree.tree{uid}.attributes{varargin{4}(1)}; 76 else 77 varargout{1} = {}; 78 for i=1:length(varargin{4}) 79 varargout{1}{i} = tree.tree{uid}.attributes{varargin{4}(i)}; 80 end 81 end 82 end 83 else 84 if length(tree.tree{uid}.attributes) == 1 85 varargout{1} = tree.tree{uid}.attributes{1}; 86 else 87 varargout{1} = {}; 88 for i=1:length(tree.tree{uid}.attributes) 89 varargout{1}{i} = tree.tree{uid}.attributes{i}; 90 end 91 end 92 end 93 case 'add' 94 %error(nargchk(5,5,nargin)); 95 ind = length(tree.tree{uid}.attributes) + 1; 96 tree.tree{uid}.attributes{ind} = struct('key',varargin{4},'val',varargin{5}); 97 varargout{1} = tree; 98 case 'del' 99 %error(nargchk(3,4,nargin)); 100 if nargin == 4 101 if ~isa(varargin{4},'double') || ... 102 any(varargin{4}>length(tree.tree{uid}.attributes)) || ... 103 any(varargin{4}<1) 104 error('[XMLTree] Invalid attribute indice.'); 105 end 106 ind = varargin{4}; 107 tree.tree{uid}.attributes(ind) = []; 108 else 109 tree.tree{uid}.attributes = []; 110 end 111 varargout{1} = tree; 112 case 'length' 113 %error(nargchk(3,3,nargin)); 114 varargout{1} = length(tree.tree{uid}.attributes); 115 otherwise 116 error('[XMLTree] Unknown method.'); 112 117 end
Note: See TracChangeset
for help on using the changeset viewer.