1 | > As of version `5.0.0` this library exposes ES modules. Use [esm](https://github.com/standard-things/esm) to consume it or a ES module aware transpiler such as Webpack, Rollup or Browserify + babelify to bundle it for the browser.
|
2 |
|
3 |
|
4 | # bpmn-moddle
|
5 |
|
6 | [![Build Status](https://travis-ci.org/bpmn-io/bpmn-moddle.svg?branch=master)](https://travis-ci.org/bpmn-io/bpmn-moddle)
|
7 |
|
8 | Read and write BPMN 2.0 diagram files in NodeJS and the browser.
|
9 |
|
10 | __bpmn-moddle__ uses the [BPMN 2.0 meta-model](http://www.omg.org/spec/BPMN/2.0/) to validate the input and produce correct BPMN 2.0 XML. The library is built on top of [moddle](https://github.com/bpmn-io/moddle) and [moddle-xml](https://github.com/bpmn-io/moddle-xml).
|
11 |
|
12 |
|
13 | ## Usage
|
14 |
|
15 | Get the library via [npm package](https://www.npmjs.org/package/bpmn-moddle). Bundle it for the web using [browserify](http://browserify.org) or [webpack](https://webpack.github.io).
|
16 |
|
17 | ```javascript
|
18 | import BpmnModdle from 'bpmn-moddle';
|
19 |
|
20 | var moddle = new BpmnModdle();
|
21 |
|
22 | var xmlStr =
|
23 | '<?xml version="1.0" encoding="UTF-8"?>' +
|
24 | '<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
25 | 'id="empty-definitions" ' +
|
26 | 'targetNamespace="http://bpmn.io/schema/bpmn">' +
|
27 | '</bpmn2:definitions>';
|
28 |
|
29 |
|
30 | moddle.fromXML(xmlStr, function(err, definitions) {
|
31 |
|
32 | // update id attribute
|
33 | definitions.set('id', 'NEW ID');
|
34 |
|
35 | // add a root element
|
36 | var bpmnProcess = moddle.create('bpmn:Process', { id: 'MyProcess_1' });
|
37 | definitions.get('rootElements').push(bpmnProcess);
|
38 |
|
39 | moddle.toXML(definitions, function(err, xmlStrUpdated) {
|
40 |
|
41 | // xmlStrUpdated contains new id and the added process
|
42 |
|
43 | });
|
44 |
|
45 | });
|
46 | ```
|
47 |
|
48 |
|
49 | ## Resources
|
50 |
|
51 | * [Issues](https://github.com/bpmn-io/bpmn-moddle/issues)
|
52 | * [Examples](https://github.com/bpmn-io/bpmn-moddle/tree/master/test/spec/xml)
|
53 | * [Changelog](./CHANGELOG.md)
|
54 |
|
55 |
|
56 | ## Building the Project
|
57 |
|
58 | To run the test suite that includes XSD schema validation you must have a Java JDK installed and properly exposed through the `JAVA_HOME` variable.
|
59 |
|
60 | Execute the test via
|
61 |
|
62 | ```
|
63 | npm test
|
64 | ```
|
65 |
|
66 | Perform a complete build of the application via
|
67 |
|
68 | ```
|
69 | npm run all
|
70 | ```
|
71 |
|
72 |
|
73 | ## License
|
74 |
|
75 | Use under the terms of the [MIT license](http://opensource.org/licenses/MIT).
|