Generate BPMN XML with Javascript

1.6k views Asked by At

i want to generate an BPMN XML file like these:

  <?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions     xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
  <bpmn:process id="Process_1" isExecutable="false">
  <bpmn:startEvent id="StartEvent_1">
  <bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
    </bpmn:startEvent>
   <bpmn:task id="Task_1" name="Titulo111">
   <bpmn:incoming>SequenceFlow_1</bpmn:incoming>
 <extensionElements>abc</extensionElements>
</bpmn:task>
  <bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="Task_1" />
 </bpmn:process>
 <bpmndi:BPMNDiagram id="BPMNDiagram_1">
 <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
  <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
    <dc:Bounds x="173" y="102" width="36" height="36" />
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
    <dc:Bounds x="437" y="107" width="100" height="80" />
  </bpmndi:BPMNShape>
  <bpmndi:BPMNEdge id="SequenceFlow_1_di" bpmnElement="SequenceFlow_1">
    <di:waypoint xsi:type="dc:Point" x="209" y="120" />
    <di:waypoint xsi:type="dc:Point" x="323" y="120" />
    <di:waypoint xsi:type="dc:Point" x="323" y="147" />
    <di:waypoint xsi:type="dc:Point" x="437" y="147" />
    <bpmndi:BPMNLabel>
      <dc:Bounds x="278" y="123.5" width="90" height="20" />
    </bpmndi:BPMNLabel>
  </bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>

Is there any way to do this with javascript? I tried with createElement but i can't set the attribute after the ":" like " <bpmn:process ... ></bpmn:process> "

Thanks in advance.

2

There are 2 answers

1
Greg Harley On BEST ANSWER

Take a look at the bpmn.io project (http://bpmn.io/). It includes a javascript library to generate BPMN as well as a modeling and rendering module (for BPMN).

0
POZ On

FYI: the text before the colon character denotes a XML name space (bpmn in your case) so you will need to make sure that you add it to your XML root element: xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"

You may want to take a look at this article (quoted from this original post) for more information on how to create a XML document with name spaces in JS.

Hope this helps,