I write some data into a XML-file:
[FileName,PathName] = uiputfile('*.xml','Select the XML file');
if length(FileName) > 3
completePath = [PathName FileName];
% Create the DOM-Object
docNode = com.mathworks.xml.XMLUtils.createDocument('docRootNode');
docRootNode = docNode.getDocumentElement;
docRootNode.setAttribute('version','2.0');
mElement = docNode.createElement('Data1');
docRootNode.appendChild(mElement)
fields = fieldnames(struct1);
for i = 1:numel(fields)
thisElement = docNode.createElement(fields{i});
thisElement.appendChild...
(docNode.createTextNode(struct1.(fields{i}))); %NO ERROR
mElement.appendChild(thisElement);
end
rElement = docNode.createElement('Data2');
docRootNode.appendChild(rElement)
fields = fieldnames(struct2);
for i = 1:numel(fields)
thisElement = docNode.createElement(fields{i});
thisElement.appendChild...
(docNode.createTextNode(struct2.(fields{i}))); %ERROR
rElement.appendChild(thisElement);
end
xmlwrite(completePath, docNode);
end
Last week it worked without any problems, but since today I get this error in the line tagged with %ERROR
running my code:
No method 'createTextNode' with matching signature found for class 'org.apache.xerces.dom.DocumentImpl'.
I did not find any solution searching the internet (a problem might be that I am no admin on my PC).
I also do not understand, why I got no error in the upper part (%NO ERROR
)
My problem is solved with the support of MATLAB:
The only problem in my program was, that struct2
contained integer values.
struct1
contained only string-values, so there was no problem.
I use num2str
to convert the numeric values now and have no problem anymore ;).