Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaces get removed when exporting foreign diagram #1310

Closed
linus-amg opened this issue Apr 9, 2020 · 26 comments
Closed

Namespaces get removed when exporting foreign diagram #1310

linus-amg opened this issue Apr 9, 2020 · 26 comments
Assignees
Labels
bug Something isn't working export miwg Tracks BPMN compatibility issues

Comments

@linus-amg
Copy link

linus-amg commented Apr 9, 2020

Describe the Bug

A diagram I exported from a different Modeler and afterwards imported into bpmn-js is not schema valid anymore as soon as I export it from bpmn-js.

This issue is coming from running tests for the upcoming bpmn miwg demo.

Fixtures
Advertise a job vacancy.original.edit.bpmn.zip

Steps to Reproduce

  1. Have a look at the attached xml and see that xmlns:dc, xmlns:di and xmlns:bpmndi are part of <defintions>
  2. Import attached XML into a bpmn-js instance
  3. use the saveXML method of the bpmn-js instance to get the xml
  4. see that the xmlns:dc, xmlns:di and xmlns:bpmndi attributes are not present in the definitions anymore

I tried to create a showcase: https://codesandbox.io/s/busy-dawn-eel38?file=/src/index.js just have a look at the console tab to see the different attributes before and after import+export.

Expected Behavior

I expected the 3 mentioned namespaces to still be inside definitions, so importing and exporting this model which was created in a different modeler is still schema-valid.

Impact
It's a blocker for the bpmn miwg demo because we cannot import models from CaseAgile and export them, to make the roundtrip.

Environment

  • OS: Linux, MacOS
  • Library version: 6.4.1
    Also tried Camunda Modeler 3.7, 4 and Cawemo and results are the same.
@linus-amg linus-amg added the bug Something isn't working label Apr 9, 2020
nikku added a commit to bpmn-io/moddle-xml that referenced this issue Apr 10, 2020
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 10, 2020
@nikku nikku added the ready Ready to be worked on label Apr 10, 2020
@nikku
Copy link
Member

nikku commented Apr 10, 2020

Added basic reproducible test cases in bpmn-moddle as well as moddle-xml.

We'll look into this.

Our tools should not ever export invalid XML, no matter how cryptic / special the input XML is.

@falko
Copy link
Member

falko commented Apr 13, 2020

@nikku thank you for looking into this!

@falko
Copy link
Member

falko commented Apr 13, 2020

When trying to root cause this, I made an observation:
The attached BPMN file uses elements from the BPMN semantic namespace without a namespace prefix and correctly declares that namespace using xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" on the definitions root element. So that looks fine.
In addition, it defines the prefix semantic for the same namespace through xmlns:semantic="http://www.omg.org/spec/BPMN/20100524/MODEL" but never uses it. Technically that's useless but not invalid. However, we start using that prefix when we export that file. While that's also not invalid, such behavior could lead to problems for people who work with branching and merging, e.g. in Git, because almost every line of the file is changed.

Removing the unused namespace semantic prefix makes the modeler keep the unprefixed elements. However, it does not fix the issue of the missing bpmndi, di, and dc namespace prefix declarations. So maybe this observation is even a separate issue.

@nikku
Copy link
Member

nikku commented Apr 13, 2020

I've already root caused these things, too.

See linked, focussed test cases attached.

Regarding the namespaces and the specific example, what namespace exports would you expect?

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<definitions id="Definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" targetNamespace="http://bpmn.io">
  <BPMNDiagram id="BPMNDiagram_1" xmlns="http://www.omg.org/spec/BPMN/20100524/DI">
    <BPMNPlane bpmnElement="Definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/DI" />
  </BPMNDiagram>
</definitions> 

@nikku
Copy link
Member

nikku commented Apr 13, 2020

In addition, it defines the prefix semantic for the same namespace through xmlns:semantic="http://www.omg.org/spec/BPMN/20100524/MODEL" but never uses it. Technically that's useless but not invalid. However, we start using that prefix when we export that file. While that's also not invalid, such behavior could lead to problems for people who work with branching and merging, e.g. in Git, because almost every line of the file is changed.

As you mentioned, this is a different issue.

@falko
Copy link
Member

falko commented Apr 13, 2020

Regarding the namespaces and the specific example, what namespace exports would you expect?

The namespaces that are used in the model. In particular, the namespace prefixes bpmndi, di, and dc were undeclared. Schema validation can be used to verify.

@nikku
Copy link
Member

nikku commented Apr 13, 2020

So the export would look as imported?

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<definitions id="Definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" targetNamespace="http://bpmn.io">
  <BPMNDiagram id="BPMNDiagram_1" xmlns="http://www.omg.org/spec/BPMN/20100524/DI">
    <BPMNPlane bpmnElement="Definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/DI" />
  </BPMNDiagram>
</definitions> 

Or should it drop the unused / not needed bpmndi namespace?

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<definitions id="Definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" targetNamespace="http://bpmn.io">
  <BPMNDiagram id="BPMNDiagram_1" xmlns="http://www.omg.org/spec/BPMN/20100524/DI">
    <BPMNPlane bpmnElement="Definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/DI" />
  </BPMNDiagram>
</definitions> 

@falko
Copy link
Member

falko commented Apr 13, 2020

Ideally, it looks like the imported: no namespace prefixes but xmlns attributes on elements. A bonus would be to remove unused namespace declarations.

If it is too hard to remember if the DI elements were prefixed or not, we could also export them always with prefix but also declare it properly.

@nikku
Copy link
Member

nikku commented Apr 14, 2020

Thanks! Your feedback helps to move towards a usable solution.

@falko
Copy link
Member

falko commented Apr 14, 2020

Just a thought: Maybe filtering out unused namespace prefix declaration before the import could help to focus on the right prefixes to remember for the export.

@nikku
Copy link
Member

nikku commented Apr 14, 2020

Just a thought: Maybe filtering out unused namespace prefix declaration before the import could help to focus on the right prefixes to remember for the export.

This is an implementation detail we don't have to care about at this point. What is more important is the what and you've helped us tremendously setting that straight.

When it comes to fixing this bug: We've queued it into our "tasks to work on" topic list. We do not have any concrete plans when it will be fixed.

@falko
Copy link
Member

falko commented Apr 14, 2020

If you can not fix it any time soon, what could be a workaround, i.e. what could we ask CaseAgile to change in their export? Would it help if their tool would prefix the DI elements? It could save some file size, given how often the xmlns attribute has to be put in the DI section of the XML.

@nikku
Copy link
Member

nikku commented Apr 14, 2020

What is your time line, i.e. when would you need a fix?

We'll not fix this right now but we'll look into this in an orderly manner, in the near future.

@nikku
Copy link
Member

nikku commented Apr 14, 2020

CaseAgile could export their diagrams in the normal manner:

<definitions xmlns:bpmndi="...">
  <bpmndi:BPMNDiagram>...</bpmndi:BPMNDiagram>
</definitions>

Rather than attaching the namespace on each element indivually AND writing the xmlns:bpmndi namespace information:

<definitions xmlns:bpmndi="...">
  <BPMNDiagram xmlns="...">...</bpmndi:BPMNDiagram>
</definitions>

But it is really a bug on our side we need to fix, too.

nikku added a commit to bpmn-io/moddle-xml that referenced this issue Apr 14, 2020
This ensures that we always use the inner most form for namespace
declarations in cases where namespaces are declared multiple times, with
different prefixes:

```xml
<root:complexNesting xmlns:root="http://properties" id="ComplexNesting">
  <complexNesting xmlns="http://properties">
    <complexNesting>
      <foo:complexNesting xmlns:foo="http://properties" />
    </complexNesting>
  </complexNesting>
</root:complexNesting>
```

Outer, unused declarations are still cleaned up accordingly, as this is
our existing behavior.

This means that we never export something like this (because we strip
the global, unused declaration):

```xml
<root xmlns="http://extended" xmlns:unused="http://properties"
id="Root">
  <base xmlns="http://properties" />
</root>
```

Related to bpmn-io/bpmn-js#1310
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 14, 2020
This adds a test that verifies that locally re-declared namespaces are
kept (to keep diagram changes to a minimum).

Related to bpmn-io/bpmn-js#1310
nikku added a commit to bpmn-io/moddle-xml that referenced this issue Apr 14, 2020
This ensures that we always use the inner most form for namespace
declarations in cases where namespaces are declared multiple times, with
different prefixes:

```xml
<root:complexNesting xmlns:root="http://properties" id="ComplexNesting">
  <complexNesting xmlns="http://properties">
    <complexNesting>
      <foo:complexNesting xmlns:foo="http://properties" />
    </complexNesting>
  </complexNesting>
</root:complexNesting>
```

Outer, unused declarations are still cleaned up accordingly, as this is
our existing behavior.

This means that we never export something like this (because we strip
the global, unused declaration):

```xml
<root xmlns="http://extended" xmlns:unused="http://properties"
id="Root">
  <base xmlns="http://properties" />
</root>
```

Related to bpmn-io/bpmn-js#1310
nikku added a commit to bpmn-io/moddle-xml that referenced this issue Apr 14, 2020
This ensures that we always use the inner most form for namespace
declarations in cases where namespaces are declared multiple times, with
different prefixes:

```xml
<root:complexNesting xmlns:root="http://properties" id="ComplexNesting">
  <complexNesting xmlns="http://properties">
    <complexNesting>
      <foo:complexNesting xmlns:foo="http://properties" />
    </complexNesting>
  </complexNesting>
</root:complexNesting>
```

Outer, unused declarations are still cleaned up accordingly, as this is
our existing behavior.

This means that we never export something like this (because we strip
the global, unused declaration):

```xml
<root xmlns="http://extended" xmlns:unused="http://properties"
id="Root">
  <base xmlns="http://properties" />
</root>
```

Related to bpmn-io/bpmn-js#1310
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 14, 2020
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 14, 2020
This adds a test that verifies that locally re-declared namespaces are
kept (to keep diagram changes to a minimum).

Related to bpmn-io/bpmn-js#1310
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 14, 2020
fake-join bot pushed a commit to bpmn-io/moddle-xml that referenced this issue Apr 15, 2020
This ensures that we always use the inner most form for namespace
declarations in cases where namespaces are declared multiple times, with
different prefixes:

```xml
<root:complexNesting xmlns:root="http://properties" id="ComplexNesting">
  <complexNesting xmlns="http://properties">
    <complexNesting>
      <foo:complexNesting xmlns:foo="http://properties" />
    </complexNesting>
  </complexNesting>
</root:complexNesting>
```

Outer, unused declarations are still cleaned up accordingly, as this is
our existing behavior.

This means that we never export something like this (because we strip
the global, unused declaration):

```xml
<root xmlns="http://extended" xmlns:unused="http://properties"
id="Root">
  <base xmlns="http://properties" />
</root>
```

Related to bpmn-io/bpmn-js#1310
fake-join bot pushed a commit to bpmn-io/moddle-xml that referenced this issue Apr 15, 2020
This ensures that we always use the inner most form for namespace
declarations in cases where namespaces are declared multiple times, with
different prefixes:

```xml
<root:complexNesting xmlns:root="http://properties" id="ComplexNesting">
  <complexNesting xmlns="http://properties">
    <complexNesting>
      <foo:complexNesting xmlns:foo="http://properties" />
    </complexNesting>
  </complexNesting>
</root:complexNesting>
```

Outer, unused declarations are still cleaned up accordingly, as this is
our existing behavior.

This means that we never export something like this (because we strip
the global, unused declaration):

```xml
<root xmlns="http://extended" xmlns:unused="http://properties"
id="Root">
  <base xmlns="http://properties" />
</root>
```

Related to bpmn-io/bpmn-js#1310
@nikku
Copy link
Member

nikku commented Apr 16, 2020

... (1) and (2).

nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 16, 2020
@nikku nikku added the ready Ready to be worked on label Apr 20, 2020 — with bpmn-io-tasks
@oguzeroglu oguzeroglu self-assigned this Apr 21, 2020
@oguzeroglu oguzeroglu added in progress Currently worked on and removed ready Ready to be worked on labels Apr 21, 2020
@ChrisSchoe
Copy link

Just fyi, we'd also be interested in an eventual fix for this issue. Our viadee BPMN modeler for Confluence also uses bpmn-js and it'd make our participation in the miwg demo much easier.

@oguzeroglu
Copy link
Contributor

We're working on a fix and planning to merge the fix within this week.

oguzeroglu added a commit to bpmn-io/moddle-xml that referenced this issue Apr 27, 2020
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 27, 2020
nikku pushed a commit to bpmn-io/moddle-xml that referenced this issue Apr 27, 2020
nikku pushed a commit to bpmn-io/moddle-xml that referenced this issue Apr 27, 2020
nikku pushed a commit to bpmn-io/moddle-xml that referenced this issue Apr 27, 2020
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 27, 2020
nikku added a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 27, 2020
nikku added a commit that referenced this issue Apr 27, 2020
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Apr 27, 2020
fake-join bot pushed a commit to bpmn-io/bpmn-moddle that referenced this issue Apr 28, 2020
fake-join bot pushed a commit that referenced this issue Apr 28, 2020
@oguzeroglu
Copy link
Contributor

Closed via #1317

@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Apr 28, 2020
@nikku nikku added export miwg Tracks BPMN compatibility issues labels Apr 28, 2020
@falko
Copy link
Member

falko commented Apr 28, 2020

Awesome! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working export miwg Tracks BPMN compatibility issues
Projects
None yet
Development

No branches or pull requests

5 participants