MATLAB: SetXmlStandalone bug

xmlxmlstandalone

Hi, I have this problem. If I make this in matlab
docNode = com.mathworks.xml.XMLUtils.createDocument('root');
docNode.setXmlStandalone(1);
docNode.setXmlVersion('1.1');
xmlWrite('file.xml',docNode);
—-
I don't see any "standalone" atttribute, and the version is still set to '1.0'.
i.e. the 'file.xml' looks like:
'<?xml version="1.0" encoding="utf-8"?> root/'
but it should look like:
'<?xml version="1.1" standalone="yes" encoding="utf-8"?> root/
Is it a bug in matlab, or am I doing something wrong? Thanks.
I'm using Matlab 2009b (7.9.0).

Best Answer

Our implementation doesn't forward that document property to the serializer. You'll have to do it yourself, like this:
docNode = com.mathworks.xml.XMLUtils.createDocument('AddressBook');
%don't do this docNode.setXmlStandalone(1)
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
tfactory = TransformerFactory.newInstance;
serializer = tfactory.newTransformer;
src = DOMSource(docNode);
stream = java.io.StringWriter;
dst = StreamResult(stream);
%set the value here instead
serializer.setOutputProperty(OutputKeys.STANDALONE,'yes');
serializer.setOutputProperty(OutputKeys.VERSION,'1.1');
serializer.transform(src,dst);
result = char(stream.toString)