How to access the text XML of the diagram

Hello,
I have difficulties exporting the xml text of a modeler.

My code is :

let bpmnXML = '...' This is a sample xml text.
let modeler = new BpmnJS({ container: '#canvas'});

modeler.importXML(bpmnXML, function(err) { if (!err) { var canvas = modeler.get('canvas'); canvas.zoom('fit-viewport'); } return false; });

The diagram is well displayed in the modeler. Then I draw a few more shapes and I would like to get the updated XML as a string.

I have tried the following :

modeler.saveXML({ format: true }, function(err, updatedXML) { if (!err){ console.log(updatedXML); } return false; });
But it return the error : Error: no definitions loaded

Does anyone know what I am doing wrong ?
Thanks a lot
Thomas

I think what you can do is to try with toXML

try below code

 modeler.moddle.toXML(modeler.definitions, { format: true }, function (err, updatedXML) {
            console.log(updatedXML)
        })

For me above code is working.

Thanks,
Mrunal

1 Like

Thanks Mrunal. This has worked.