2

I'm using JavaScript with MxGraph to create a simple client-side diagramming tool for my final-year university project. I'm very new to both JS and mxGraph. I need to generate te mxGraph graph's XML description, and save it as a .xml file to my local laptop disk.

I have mxGraph installed on my laptop and need to do everything locally (no server access). So far I've managed to generate "Pretty" XML and show it in a modal window on the screen using this JS function:

         function showPrettyXml(graph)
         {
        /* Call Stack: ONCLICK event handler on MAIN.SHOWDIAGRAM button   */

            var textarea = document.createElement('textarea');
            textarea.style.width = '400px';
            textarea.style.height = '400px';
            var enc = new mxCodec(mxUtils.createXmlDocument());
            var node = enc.encode(graph.getModel());
            textarea.value = mxUtils.getPrettyXml(node);
            showModalWindow(graph, 'XML', textarea, 410, 440);
         };

         // showModalWindow function defines the documents popup modal window and works fine

All these mxGraph calls work fine. But how can I save the XML to my local disk ? I've found several suggestions for this, on StackOverflow and elsewhere, but they either save to a server via an URL, or involve lots of complex programming which I don't have time or brain to do. The complexity seems to be that JS is really designed for server-side storage, not local.

This is a purely JavaScript question not mxGraph; I can get the graph XML into a JS variable no problem. My problem is how then to save the value of this JS variable to local disk. I'm hoping (!) there's just a few lines of JS code to do it.

Many thanks.

Berkan
  • 31
  • 1

0 Answers0