xmlmxgraph

mxGraph: loading XML file


I'm new to mxGraph. Does anyone know how to save a file to my local storage from mxGraph editor (http://jgraph.github.io/mxgraph/javascript/examples/grapheditor/www/index.html)? BTW, are XML files created with draw.io compatible with mxGraph? Thanks.


Solution

  • Use Codec and Encoder.

    var encoder = new mxCodec();
    var node = encoder.encode(graph.getModel()); 
    

    variable node will have XML of your graph.

    Use mxGraph utility to instantly show XML in popup.

    mxUtils.popup(mxUtils.getPrettyXml(node), true);