0

I took some idea from this https://github.com/sibaspage/mxgraph-with-angular2.git. I can run this code on my machine. I have created a graph on editor then I have exported that in xml. Now I want to import same xml on editor and want same graph back on editor.

Export and save working fine now, but when I click on import it open again a new graph instance.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nisha Yadav
  • 49
  • 2
  • 7

1 Answers1

0

Code for XML to diagram:

let doc = mxUtils.parseXml(xml);
let codec = new mxCodec(doc);
codec.decode(doc.documentElement, graph.getModel());
let elt = doc.documentElement.firstChild;
let cells = [];
while (elt != null)
{   
    let cell = codec.decode(elt)
    if(cell != undefined){
            if(cell.id != undefined && cell.parent != undefined && (cell.id == cell.parent)){
                elt = elt.nextSibling;
                continue;
            }
            cells.push(cell);
    }
    elt = elt.nextSibling;
}
graph.addCells(cells);

Referred here

Bala
  • 618
  • 5
  • 21