0

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)

  • yes, because createTextNode is not a class in org.apache, you want to use com.mathworks.xml.createDocument.createTextNode; ALSO I noticed that you set your root element to 'docRootNode' and then immediately set that into docNode.getDocumentElement. you might want to fix this first. – GameOfThrows Jan 26 '16 at 15:18
  • @GameOfThrows I understand the problem, but I don't really see how to fix it. Why does matlab want to use 'org.apache...' although my docNode is 'com.mathworks...' I changed the other point you mentioned ;). – fritzleone Jan 26 '16 at 15:35
  • It will automatically look into other libraries if it did not find it on your specified path, it is part of a resolving process. Try putting in the full path when you call the function createTextNode and see what happens, if it still outputs this error, then you will need to contact Matlab support. – GameOfThrows Jan 26 '16 at 15:48
  • I still get this error, so I will contact Matlab support. Thanks – fritzleone Jan 26 '16 at 16:02

1 Answers1

0

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 ;).