Changeset 925 for trunk/src/@xmltree/add.m
- Timestamp:
- Feb 17, 2016, 12:52:48 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/add.m
r723 r925 13 13 % tree = add(tree,uid,type,parameter); 14 14 % [tree, new_uid] = add(tree,uid,type,parameter); 15 %_______________________________________________________________________ 15 %__________________________________________________________________________ 16 16 % 17 17 % Add a node (element, chardata, cdata, pi or comment) in the XML Tree. … … 20 20 % deal with the attributes of an element node (initialized empty). 21 21 % The tree parameter must be in input AND in output. 22 %_______________________________________________________________________ 23 % @(#)add.m Guillaume Flandin 02/03/2922 %__________________________________________________________________________ 23 % Copyright (C) 2002-2011 http://www.artefact.tk/ 24 24 25 error(nargchk(4,4,nargin)); 25 % Guillaume Flandin 26 % $Id: add.m 4460 2011-09-05 14:52:16Z guillaume $ 27 26 28 27 29 if ~isa(uid,'double') 28 30 error('[XMLTree] UID must be a double array.'); 29 31 end 30 32 if ~ischar(type) 31 33 error('[XMLTree] TYPE must be a valid item type.'); 32 34 end 33 35 if strcmp(type,'pi') 34 if ~isfield(parameter,'target') | ~isfield(parameter,'value')| ...35 ~ischar(parameter.target)| ~ischar(parameter.value)36 error('[XMLTree] For a Processing Instruction, ',...37 'PARAMETER must be a struct.');38 36 if ~isfield(parameter,'target') || ~isfield(parameter,'value') || ... 37 ~ischar(parameter.target) || ~ischar(parameter.value) 38 error(['[XMLTree] For a Processing Instruction, ',... 39 'PARAMETER must be a struct.']); 40 end 39 41 elseif ~ischar(parameter) 40 42 error('[XMLTree] PARAMETER must be a string.'); 41 43 end 42 44 43 45 if nargout == 2 44 45 varargout{2} = (l+1):(l+prod(size(uid)));46 l = length(tree.tree); 47 varargout{2} = (l+1):(l+numel(uid)); 46 48 end 47 49 48 for i=1: prod(size(uid))49 if uid(i)<1| uid(i)>length(tree.tree)50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 50 for i=1:numel(uid) 51 if uid(i)<1 || uid(i)>length(tree.tree) 52 error('[XMLTree] Invalid UID.'); 53 end 54 if ~strcmp(tree.tree{uid(i)}.type,'element') 55 error('[XMLTree] Cannot add a child to a non-element node.'); 56 end 57 l = length(tree.tree); 58 switch type 59 case 'element' 60 tree.tree{l+1} = struct('type','element',... 61 'name',parameter,... 62 'attributes',[],... 63 'contents',[],... 64 'parent',[],... 65 'uid',l+1); 66 case 'chardata' 67 tree.tree{l+1} = struct('type','chardata',... 68 'value',parameter,... 69 'parent',[],... 70 'uid',l+1); 71 case 'cdata' 72 tree.tree{l+1} = struct('type','cdata',... 73 'value',parameter,... 74 'parent',[],... 75 'uid',l+1); 76 case 'pi' 77 tree.tree{l+1} = struct('type','pi',... 78 'target',parameter.target,... 79 'value',parameter.value,... 80 'parent',[],... 81 'uid',l+1); 82 case 'comment' 83 tree.tree{l+1} = struct('type','comment',... 84 'value',parameter,... 85 'parent',[],... 86 'uid',l+1); 87 otherwise 88 error(sprintf('[XMLTree] %s: unknown item type.',type)); 89 end 90 tree.tree{uid(i)}.contents = [tree.tree{uid(i)}.contents l+1]; 91 tree.tree{l+1}.parent = uid(i); 90 92 end 91 93
Note: See TracChangeset
for help on using the changeset viewer.