Namespace not added to XML when exporting diagram with custom tags

I have extended the BPMN 2.0 tags the same way as in your [custom meta model example][1]

[1]: But when the diagram is exported to XML the custom namespace doesn’t get added to the XML namespaces definitions. That is I don’t get this at the top of the XML:

What I am missing here?

I just did the same thing and the custom xmlns is getting added for me.

I’m sure you are doing this but when you open a new diagram to draw from does that diagram have your custom xmlns added (xmlns:cutomNs=“http://some-company/schema/bpmn/cutomNs”) or are you using the default?

If i create a new diagram or open an existing .bpmn file that already has the namespace it gets preserved, so that scenario is ok.

The problem is when opening an existing .bpmn file that does not yet have this namespace it. For example:

  1. I open an existing .bpmn file that does not yet have the custom namespace
  2. I add some elements from the custom namespace to the diagram (in code)
  3. When exporting the .bpmn file it still does not have the custom namespace (even if now there are elements from that namespace on the diagram)

Am I supposed to add this manualy myself? In code?

I have not tried doing that but I think the answer is yes. You need to have your code add in the namespace for customNs. does not have the smarts to figure out that it needs to add in the namespace.

Please show us (in code) how you are approaching this and we may be able to help you.

Hmmm I tried to recreate the issue today but it all seems to work correctly now :slight_smile: now adds the missing namespace if it is used anywhere.
Maybe it was something in our code or the fact that we recently upgraded to version 0.12.1.

Thanks anyway, and sorry for the inconvenience.

Now I’ve narrowed down the problem.

If the custom namespace (‘myNs’) is only used in an attribute value then doesn’t add the custom namespace to the generated XML.

<bpmn:itemDefinition id="dhgdfhdfghd" structureRef="myNs:Text" />
<bpmn:process id="Process_1" isExecutable="false">
    <bpmn:startEvent id="StartEvent_1" />

On the other hand if the diagram contains actual elements from the custom namespace then adds the custom namespace to the generated XML.

  <bpmn:itemDefinition id="jkklč" structureRef="myNs:Composite">
      <myNs:structure id="ID_1ylwh5t">
        <myNs:fieldDefinition id="ID_17mmmpa" name="dfgd" description="dfgdg" type="Text" />
  <bpmn:process id="Process_1" isExecutable="false">
    <bpmn:startEvent id="StartEvent_1" />

Is there a way to force the modeler to always include this namespace when exporting to XML?
I tried this:

 renderer.definitions.set("xmlns:myNs", "http://...");

but it does not work.

This is a bug. Thanks for reporting!

Fixed with latest bpmn-moddle release.

1 Like

Great!. Any chance for a new release of the pre-packaged version?

We will release a new version of bpmn-js, including the pre-packaged version, within the next weeks.

This still does not work properly for me.

With the given XML:

<bpmn:itemDefinition id="dhgdfhdfghd" structureRef="myNs:Text" />
<bpmn:process id="Process_1" isExecutable="false">
    <bpmn:startEvent id="StartEvent_1" />

And executing:
renderer.definitions.set("xmlns:myNs", "http://...");
the modeler does NOT add the “xmlns:myNs” namespace to the exported XML.
Fot this namespace I’m also extending the modeler:

this.renderer = new bpmnEditor({
    container: canvas,
    moddleExtensions: {
        myNs: customEntityExtensions

But… executing this:
renderer.definitions.set("xmlns:dummyNs", "http://...");
the modeler does add the “xmlns:dummyNs” namespace to the exported XML.
In this case no moddleExtensions were defined.

It seems that the modeler does not allow manual insertion of namespaces that are defined with moddleExtensions. Does this seem possible?

Works in our test suite and got released with bpmn-js v0.13.0.

I’ve prepared an example that demonstrates my issue:

A little explanation of what this jsfiddle example does:

  1. Initialize modeler v0.13.1 with custom moddleExtensions for namespace “myNS”
  2. Load example diagram
  3. Manually add namespaces “myNS” and “dummyNS” to definitions
  4. Export diagram and trigger download

Can you please take a look?
Observe that one namespace gets added and the other does not.

With the last fix we allow the addition of custom namespaces. We still verify whether myNS is used because you defined it (via a meta-model extension).

To fix your issue we’d need to properly parse and recognize the namespace in ItemDefinition#structureRef (open bug).

If you have a well-defined namespace (meta-model extension) you may work around this by adding a custom extension element to the root element.