Install bpmn-moddle via npm
mainYou can install bpmn-moddle using npm to use it in NodeJS or to bundle it for the browser using your preferred build tool.
npm install bpmn-moddlerepository·main·Indexed 19 days ago
https://github.com/bpmn-io/bpmn-moddleA moddle wrapper for BPMN 2.0 used for reading and writing BPMN 2.0 diagram files in NodeJS and browser environments. It provides the BpmnModdle class to parse XML strings into a JavaScript object model via fromXML(), create new elements via create(), and serialize models back to XML via toXML(), ensuring compliance with the BPMN 2.0 meta-model.
You can install bpmn-moddle using npm to use it in NodeJS or to bundle it for the browser using your preferred build tool.
npm install bpmn-moddleThe BpmnModdle class allows you to parse BPMN 2.0 XML strings into a JavaScript object model and convert that model back into valid BPMN 2.0 XML. It uses the official BPMN 2.0 meta-model to ensure validation and correctness.
Key workflows:
moddle.fromXML(xmlString) to get the root element..set(key, value) to update attributes and .get(key) to retrieve elements. Use moddle.create(type, properties) to instantiate new BPMN elements.moddle.toXML(rootElement) to generate the updated XML string.import { BpmnModdle } from 'bpmn-moddle';
const moddle = new BpmnModdle();
const xmlStr =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
'id="empty-definitions" ' +
'targetNamespace="http://bpmn.io/schema/bpmn">' +
'</bpmn2:definitions>';
// Parse XML
const {
rootElement: definitions
} = await moddle.fromXML(xmlStr);
// Update an attribute
definitions.set('id', 'NEW ID');
// Create and add a new element
const bpmnProcess = moddle.create('bpmn:Process', { id: 'MyProcess_1' });
definitions.get('rootElements').push(bpmnProcess);
// Convert back to XML
const {
xml: xmlStrUpdated
} = await moddle.toXML(definitions);The BpmnModdle class is the primary entry point for the library. It provides methods for XML parsing and serialization based on the BPMN 2.0 meta-model.
fromXML(xml): Asynchronously parses an XML string. Returns an object containing the rootElement.toXML(element): Asynchronously serializes a BPMN element back to an XML string. Returns an object containing the xml string.create(type, properties): Creates a new BPMN element of the specified type with the provided properties.The BpmnModdle class is the primary entrypoint for the library. It provides the functionality required to parse BPMN 2.0 XML into a JavaScript object model and to write a JavaScript object model back into BPMN 2.0 XML. It is exported as the default export from the package.
import BpmnModdle from 'bpmn-moddle';
const moddle = new BpmnModdle();
// Example usage (conceptual):
// const modeling = await moddle.fromXML(xmlString);
// const { xml } = await moddle.toXML(modeling);