Index: trunk/src/@xmltree/add.m
===================================================================
--- trunk/src/@xmltree/add.m	(revision 723)
+++ trunk/src/@xmltree/add.m	(revision 925)
@@ -13,5 +13,5 @@
 %        tree = add(tree,uid,type,parameter);
 %        [tree, new_uid] = add(tree,uid,type,parameter);
-%_______________________________________________________________________
+%__________________________________________________________________________
 %
 % Add a node (element, chardata, cdata, pi or comment) in the XML Tree.
@@ -20,72 +20,74 @@
 % deal with the attributes of an element node (initialized empty).
 % The tree parameter must be in input AND in output.
-%_______________________________________________________________________
-% @(#)add.m                   Guillaume Flandin                02/03/29
+%__________________________________________________________________________
+% Copyright (C) 2002-2011  http://www.artefact.tk/
 
-error(nargchk(4,4,nargin));
+% Guillaume Flandin
+% $Id: add.m 4460 2011-09-05 14:52:16Z guillaume $
+
 
 if ~isa(uid,'double')
-	error('[XMLTree] UID must be a double array.');
+    error('[XMLTree] UID must be a double array.');
 end
 if ~ischar(type)
-	error('[XMLTree] TYPE must be a valid item type.');
+    error('[XMLTree] TYPE must be a valid item type.');
 end
 if strcmp(type,'pi')
-	if ~isfield(parameter,'target') | ~isfield(parameter,'value') | ...
-	   ~ischar(parameter.target) | ~ischar(parameter.value)
-		error('[XMLTree] For a Processing Instruction, ',...
-						'PARAMETER must be a struct.');
-	end
+    if ~isfield(parameter,'target') || ~isfield(parameter,'value') || ...
+       ~ischar(parameter.target) || ~ischar(parameter.value)
+        error(['[XMLTree] For a Processing Instruction, ',...
+                        'PARAMETER must be a struct.']);
+    end
 elseif ~ischar(parameter)
-	error('[XMLTree] PARAMETER must be a string.');
+    error('[XMLTree] PARAMETER must be a string.');
 end
 
 if nargout == 2
-	l = length(tree.tree);
-	varargout{2} = (l+1):(l+prod(size(uid)));
+    l = length(tree.tree);
+    varargout{2} = (l+1):(l+numel(uid));
 end
 
-for i=1:prod(size(uid))
-	if uid(i)<1 | uid(i)>length(tree.tree)
-		error('[XMLTree] Invalid UID.');
-	end
-	if ~strcmp(tree.tree{uid(i)}.type,'element')
-		error('[XMLTree] Cannot add a child to a non-element node.');
-	end
-	l = length(tree.tree);
-	switch type
-		case 'element'
-			tree.tree{l+1} = struct('type','element',...
-        	                        'name',parameter,...
-					                'attributes',[],...
-					                'contents',[],...
-									'parent',[],...
-					                'uid',l+1);
-		case 'chardata'
-			tree.tree{l+1} = struct('type','chardata',...
-					                'value',parameter,...
-									'parent',[],...
-					                'uid',l+1);
-		case  'cdata'
-			tree.tree{l+1} = struct('type','cdata',...
-					                'value',parameter,...
-									'parent',[],...
-					                'uid',l+1);
-		case 'pi'
-			tree.tree{l+1} = struct('type','pi',...
-									'target',parameter.target,...
-					                'value',parameter.value,...
-									'parent',[],...
-					                'uid',l+1);
-		case 'comment'
-			tree.tree{l+1} = struct('type','comment',...
-					                'value',parameter,...
-									'parent',[],...
-					                'uid',l+1);
-		otherwise
-			error(sprintf('[XMLTree] %s: unknown item type.',type));
-	end
-	tree.tree{uid(i)}.contents = [tree.tree{uid(i)}.contents l+1];
-	tree.tree{l+1}.parent = uid(i);
+for i=1:numel(uid)
+    if uid(i)<1 || uid(i)>length(tree.tree)
+        error('[XMLTree] Invalid UID.');
+    end
+    if ~strcmp(tree.tree{uid(i)}.type,'element')
+        error('[XMLTree] Cannot add a child to a non-element node.');
+    end
+    l = length(tree.tree);
+    switch type
+        case 'element'
+            tree.tree{l+1} = struct('type','element',...
+                                    'name',parameter,...
+                                    'attributes',[],...
+                                    'contents',[],...
+                                    'parent',[],...
+                                    'uid',l+1);
+        case 'chardata'
+            tree.tree{l+1} = struct('type','chardata',...
+                                    'value',parameter,...
+                                    'parent',[],...
+                                    'uid',l+1);
+        case  'cdata'
+            tree.tree{l+1} = struct('type','cdata',...
+                                    'value',parameter,...
+                                    'parent',[],...
+                                    'uid',l+1);
+        case 'pi'
+            tree.tree{l+1} = struct('type','pi',...
+                                    'target',parameter.target,...
+                                    'value',parameter.value,...
+                                    'parent',[],...
+                                    'uid',l+1);
+        case 'comment'
+            tree.tree{l+1} = struct('type','comment',...
+                                    'value',parameter,...
+                                    'parent',[],...
+                                    'uid',l+1);
+        otherwise
+            error(sprintf('[XMLTree] %s: unknown item type.',type));
+    end
+    tree.tree{uid(i)}.contents = [tree.tree{uid(i)}.contents l+1];
+    tree.tree{l+1}.parent = uid(i);
 end
 
