diff m-toolbox/classes/+utils/@xml/attachVectorToDom.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@xml/attachVectorToDom.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,52 @@
+
+function attachVectorToDom(numbers, dom, parent)
+  
+  shape = sprintf('%dx%d', size(numbers));
+  
+  %%%%%   Real data   %%%%%
+  realNode = dom.createElement('realData');
+  realNode.setAttribute('type', 'doubleVector');
+  realNode.setAttribute('shape', shape);
+
+  %%% Set the parent attribute 'type' to vector
+  parent.setAttribute('type', 'doubleVector');
+  parent.appendChild(realNode);
+  
+  idx = 1;
+  Ndata = numel(numbers);
+  n = min(utils.xml.MAX_DOUBLE_IN_ROW, Ndata);
+  while idx-1 <= Ndata
+    
+    numberStr = strtrim(utils.helper.num2str(real(numbers(idx:min(Ndata,idx+n-1)))));
+    if ~isempty(numberStr)
+      %%% Create new vector node
+      content = dom.createTextNode(numberStr);
+      vectorNode = dom.createElement('doubleVector');
+      vectorNode.setAttribute('type', class(numbers));
+      vectorNode.appendChild(content);
+      realNode.appendChild(vectorNode);
+    end
+    idx = idx + n;
+  end
+  
+  %%%%%   Imaginary data   %%%%%
+  if ~isreal(numbers)
+    imagNode = dom.createElement('imagData');
+    imagNode.setAttribute('type', 'doubleVector')
+    parent.appendChild(imagNode);
+    
+    idx   = 1;
+    while idx-1 <= Ndata
+      numberStr = strtrim(utils.helper.num2str(imag(numbers(idx:min(Ndata,idx+n-1)))));
+      if ~isempty(numberStr)
+        content = dom.createTextNode(numberStr);
+        vectorNode = dom.createElement('doubleVector');
+        vectorNode.setAttribute('type', class(numbers));
+        vectorNode.appendChild(content);
+        imagNode.appendChild(vectorNode);
+      end
+      idx = idx + n;
+    end
+  end
+  
+end