How can I add custom XML tags in a BPMN file?

719 views Asked by At

In a BPMN file there are two main components, the process and the diagram.

<?xml version="1.0" encoding="UTF-8"?> 
<definitions id="Definition"
             targetNamespace="http://www.example.org/MinimalExample"
             typeLanguage="http://www.java.com/javaTypes"
             expressionLanguage="http://www.mvel.org/2.0"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
             xs:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
             xmlns:tns="http://www.jboss.org/drools">

  <process processType="Private" isExecutable="true" id="com.sample.HelloWorld" name="Hello World" >

    <!-- nodes -->
    <startEvent id="_1" name="StartProcess" />
    <scriptTask id="_2" name="Hello" >
      <script>System.out.println("Hello World");</script>
    </scriptTask>
    <endEvent id="_3" name="EndProcess" >
        <terminateEventDefinition/>
    </endEvent>

    <!-- connections -->
    <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
    <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />

  </process>

  <bpmndi:BPMNDiagram>
    <bpmndi:BPMNPlane bpmnElement="Minimal" >
      <bpmndi:BPMNShape bpmnElement="_1" >
        <dc:Bounds x="15" y="91" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_2" >
        <dc:Bounds x="95" y="88" width="83" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" >
        <dc:Bounds x="258" y="86" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_1-_2" >
        <di:waypoint x="39" y="115" />
        <di:waypoint x="75" y="46" />
        <di:waypoint x="136" y="112" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_2-_3" >
        <di:waypoint x="136" y="112" />
        <di:waypoint x="240" y="240" />
        <di:waypoint x="282" y="110" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>

</definitions>

I am looking for a way to add a third section after the diagram part of the XML. I want to add custom XML tags so that I can run the XML through another system and have that system pick up my custom XML. I was looking for a way to edit the "definitions" tag to include third section that I can then add any XMl into. Is there an XMLSchema attribute that will let me add my tags? I would like it to look something like this:

<?xml version="1.0" encoding="UTF-8"?> 
<definitions id="Definition"...>

  <process .....  </process>

  <bpmndi:BPMNDiagram>
    <bpmndi:BPMNPlane bpmnElement="Minimal" >
      ......
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>

  <myNewSection>
    <newTag>
       <newTag2>
          ...
       </newTag2>
       <newTag3>
          ...
       </newTag3>
    </newTag>
  </myNewSection>
</definitions>
1

There are 1 answers

0
lmsurprenant On

From http://www.omg.org/spec/BPMN/20100501/BPMN20.xsd

<xsd:element name="definitions" type="tDefinitions"/>
<xsd:complexType name="tDefinitions">
    <xsd:sequence>
        <xsd:element ref="import" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="extension" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="rootElement" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="bpmndi:BPMNDiagram" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="relationship" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    ...
    <xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:complexType>

Because the tDefinitions type doesn't extend tBaseElement, its not possible to extend it with an extensionElements element, but you are free to include your own attribute extensions at will.

After looking into http://www.omg.org/spec/BPMN/20100501/Semantic.xsd, it seems that the process element is actually just one of many top-level elements in the substitutionGroup for rootElement.

Maybe go read up on XML Schema substitution groups to see if you can tap into that with an external schema or if you must be able to modify the source schema in which case you'd basically be forking the BPMN spec.

Hope this helps and please report back if you find a good way to extend the definitions element from outside the schema.