How to get the xml of a bpmn?

I would like to export the xml of a bpmn we are modeling.
I added an icon for export in the palette, and i woould like to print the xml of the current modeled bpmn into the console.

Is there a way to do it?

Yes, you can use this method.