Did you try this?
var enc = new mxCodec(mxUtils.createXmlDocument()); var node = enc.encode(graph.getModel()); var xmlString = mxUtils.getXml(node);