How to validate xml file before import

My requirement is when import xml, if xml file is invalid (like missing bpmndi:BPMNDiagram), the old bpmn is kept, and display error.
I’ve tried to try catch but the old bpmn still be cleared.
Do you have any API to validate xml file before process import?

Hi @phuongmt, welcome!

You could consider using bpmn-moddle for this. bpmn-js is using it under the hood to perform the import and maintain the model.