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.
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.
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
}