Currently, I am working on a project using javascript with Angular7 and MxGraph library. I have successfully managed to save the MxGraph model into an XML file with the following code snippet:
var enc = new mx.mxCodec(mx.mxUtils.createXmlDocument());
var node = enc.encode(editor.graph.getModel());
this.xml = mx.mxUtils.getPrettyXml(node);
However, I am facing difficulties when trying to decode the saved XML according to the documentation. Despite attempting various methods, even directly pasting the XML for decoding as shown below, I haven't been successful:
// Usually I would do this:
// var doc = mx.mxUtils.parseXml(this.xml);
// Just for testing purposes I did this
var doc = mx.mxUtils.parseXml(
'<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>'+
'<Node0 label="Input" style="container" id="input"><mxCell style="container" vertex="1" connectable="0" parent="1">'+
'<mxGeometry y="20" width="100" height="580" as="geometry"/></mxCell></Node0>'+
'</root></mxGraphModel>');
var dec = new mx.mxCodec(doc);
dec.decode(doc.documentElement, graph.getModel());
console.log(graph.getModel());
Upon further investigation, I noticed that the returned model does not include Node0
, which is puzzling.