clear all

%---
% matrix
%---

N=3;

A=[ 1 3  4;
   -3 5  6;
   -3 1 -4];

eigval=eig(A);

% create an xml java object

dehesa = com.mathworks.xml.XMLUtils.createDocument('eigenvalues');

%=================

for i=1:N

 eg    = dehesa.createElement('eigenvalue');
 eg_id = dehesa.createAttribute('id');
 eg_id.setNodeValue(sprintf('%2d',i));
 dehesa.getDocumentElement.appendChild(eg);
 eg.setAttributeNode(eg_id);

 re = dehesa.createElement('real');
 lamr = dehesa.createTextNode(sprintf('%5.3f',real(eigval(i))));
 eg.appendChild(re);
 re.appendChild(lamr);

 im   = dehesa.createElement('imaginary');
 lami = dehesa.createTextNode(sprintf('%5.3f',imag(eigval(i))));
 eg.appendChild(im);
 im.appendChild(lami);

end

xmlfile = xmlwrite(dehesa)

%=================

xmlwrite('eigen1.xml',dehesa)
