I found under the mxgraph GitHub source files exported XML file function is wrong, I would like to have a direct export of JSON data files
There is a way to get the XML of the graph by downloading xmlToJSON.js from https://github.com/metatribal/xmlToJSON.
Be sure to include this in your HTML file with
<script type="text/javascript" src="xmlToJSON.js"></script>
From there, the following code snippet should convert your XML to JSON
function parseXmlJSON (model)
{
var encoder = new mxCodec();
var node = encoder.encode(graph.getModel());
var testString = mxUtils.getXml(node); // fetch xml (string or document/node)
var result = xmlToJSON.parseString(testString); // parses to JSON object
mxUtils.popup(JSON.stringify(result, null, 4), true); // turns into string
}
Feel free to replace mxUtils.popup with console.log or alert etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With