-2

I want to add a button to export the current diagram to an xml var.

I know that there's a button to export but i didn't understand the code that it use to export.

I am a newbie in coding so please help.

Amin_prob
  • 1
  • 2

1 Answers1

0

You can save the current state of your graph object into xml format using the code below:

   var xml = "";

   let saveBtn = document.createElement('button');
   saveBtn.value = ' Save XML ' ;
   saveBtn.addEventListener('click',function(e){
       exportXML(); //on click trigger the exportXML() function;
   });

   function exportXML() {
    let encoder = new mxCodec();
    let result = encoder.encode(graph.getModel()); //where graph is the object you are using
    xml = mxUtils.getXml(result); //now the global variable 'xml' is assigned with the xml value of the graph
   }
NickAth
  • 1,089
  • 1
  • 14
  • 35
  • Thanks Nick, but is there a way to get the current graph into an xml variable; i want to add a button in index.html, when you click on it it save the current graph into a variable . – Amin_prob Jul 10 '19 at 17:16
  • @NickAth, When I use the above code I am not getting whole graph instead of but actual xml is having more detail. – Bala Jul 15 '19 at 06:12
  • Could you debug on the `graph` object? Try to console.log() the `graph.getChildCells();`, what does it return? – NickAth Jul 15 '19 at 10:35