MATLAB: Does XMLWRITE in MATLAB 7.0.4 (R14SP2) save the XML-file to a different directory than the one I specified

MATLAB

I use the following code to create an XML-file in the directory "C:\my folder" with a space in its name:
xmlwrite('C:\my folder\example.xml',docNode);
But XMLWRITE stores example.xml into a new directory named "C:\my%20folder".

Best Answer

This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
There is a bug in MATLAB 7.0.4 (R14SP2) on Windows that affects the way XMLWRITE handles path names containing spaces. To work around this issue, you can specify the file name as a URL:
xmlwrite('file:///C:/my folder/example.xml',docNode);
Alternatively, you can create the XML-file in a folder without spaces in its name, or create it in the current directory. You can then use the MOVEFILE function to move it to the desired directory, as shown in the following example:
docNode = com.mathworks.xml.XMLUtils.createDocument('root_element');
xmlwrite('C:\temp\example.xml',docNode);
movefile('C:\temp\example.xml','C:\my folder\example.xml');
If your destination directory does not yet exist, you can create it first using MKDIR as shown here:
mkdir('C:\my folder');