3

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.

Jopa
  • 35
  • 1
  • 6
  • you can use this one https://www.draw.io for saving xml to local directory – Shaybi Nov 16 '17 at 22:19
  • That's obvious. What I'm asking is how to do the same with mxGraph, I mean saving the drawing XML to local storage. – Jopa Nov 17 '17 at 22:38
  • Sorry @Jopa if im misunderstood. I have saved an XML from mxGraph and imported that XML in draw.io and it is imported correctly. but i have not tested the reverse yet. – Shaybi Nov 20 '17 at 18:30
  • @Shaybi how did you save the XML from mxGraph? – Jopa Nov 21 '17 at 14:30
  • 1
    you can user Codec and Encoder to get this done. ` var encoder = new mxCodec(); var node = encoder.encode(graph.getModel()); mxUtils.popup(mxUtils.getPrettyXml(node), true);` or just console the "node" which will contain xml. – Shaybi Nov 21 '17 at 16:33
  • It works @Shaybi. Thank you. – Jopa Nov 22 '17 at 04:57

2 Answers2

5

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);
Shaybi
  • 318
  • 2
  • 9
0

"are XML files created with draw.io compatible with mxGraph". Yes they are. See my example at mxGraph: Create graph with XML