【问题标题】:Invalid XML due to $type property由于 $type 属性,XML 无效
【发布时间】:2018-07-27 20:37:36
【问题描述】:

我最近将我的 bpmn-js 库更新到了 0.26.6 版。但是,既然我已经这样做了,我的图表就遇到了问题。

由于某种原因,在将图表解析为 XML 时,SequenceFlow 对象似乎有一个附加属性,如下所示:

<bpmn:sequenceFlow id="SequenceFlow_0itptjk" name="x===1" sourceRef="ExclusiveGateway_16fh3h3" targetRef="Task_10pxcz5" $type="bpmn:SequenceFlow">
    <bpmn:conditionExpression language="JavaScript" xsi:type="bpmn:tFormalExpression">x===1</bpmn:conditionExpression>
</bpmn:sequenceFlow>

问题在于 $type="bpmn:SequenceFlow" 不是有效的 XML,并且它没有通过验证。

{
  "name": "FlowElement",
  "isAbstract": true,
  "superClass": [
    "BaseElement"
  ],
  "properties": [
    {
      "name": "name",
      "isAttr": true,
      "type": "String"
    },
    {
      "name": "auditing",
      "type": "Auditing"
    },
    {
      "name": "monitoring",
      "type": "Monitoring"
    },
    {
      "name": "categoryValueRef",
      "type": "CategoryValue",
      "isMany": true,
      "isReference": true
    }
  ]
},{
  "name": "SequenceFlow",
  "superClass": [
    "FlowElement"
  ],
  "properties": [
    {
      "name": "isImmediate",
      "isAttr": true,
      "type": "Boolean"
    },
    {
      "name": "conditionExpression",
      "type": "Expression",
      "xml": {
        "serialize": "xsi:type"
      }
    },
    {
      "name": "sourceRef",
      "type": "FlowNode",
      "isAttr": true,
      "isReference": true
    },
    {
      "name": "targetRef",
      "type": "FlowNode",
      "isAttr": true,
      "isReference": true
    }
  ]
},{
  "name": "BaseElement",
  "isAbstract": true,
  "properties": [
    {
      "name": "id",
      "isAttr": true,
      "type": "String",
      "isId": true
    },
    {
      "name": "documentation",
      "type": "Documentation",
      "isMany": true
    },
    {
      "name": "extensionDefinitions",
      "type": "ExtensionDefinition",
      "isMany": true,
      "isReference": true
    },
    {
      "name": "extensionElements",
      "type": "ExtensionElements"
    }
  ]
}

如您所见,这些都没有说明为什么要添加 $type。

过去有没有人遇到过这个问题?

--编辑--

经过一些测试,似乎是在SequenceFlow中添加条件表达式时添加了$type参数。否则,不添加属性,并且 XML 有效。

--EDIT2--

这些是我正在使用的 XML 定义:

<bpmn:definitions id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

--EDIT3--

在更多故障排除后获得更多详细信息。似乎此错误不仅影响条件流 - 它影响所有类型。错误发生在更新之后,在

中执行
UpdatePropertiesHandler.prototype.execute = function(context) ...

在该函数内部,有一个对

的调用
setProperties(businessObject, properties);

在那套里面,有这个

function setProperties(businessObject, properties) {
  forEach(properties, function(value, key) {
    businessObject.set(key, value);
  });
}

在 forEach 之后,businessObject 突然在其 $attrs 中添加了一个 $type。就好像它不是在做businessObject.set,而是在做businessObject.$attr.set。

【问题讨论】:

  • 条件表达式是不是你写的代码加的?
  • 条件是由默认的 camunda 引擎添加的,使用 'element.updateProperties' 操作。我注意到的一件事是,在执行更新时,“oldProperties”包含一个名为“$attrs”的数组,其中包含原型。 “newProperties”包含相同的数组,但除了原型之外,它还包含导致问题的“$type”。
  • camunda 引擎=bpmn-js?如果是这样,element.updateProperties 不是在您的代码中的某处调用吗?我只是问,因为我过去解决了类似的问题,我扩展了 bpmn.io 建模器,以便让我使用 html 表单输入我的条件表达式。
  • 我正在使用的建模器是这个:raw.githubusercontent.com/bpmn-io/bower-bpmn-js/master/dist/… 对它之外的那个 .js 文件的唯一引用是在调用 toXML 执行保存到我的数据库时。我将使用我正在使用的 XML 定义更新问题。

标签: bpmn camunda bpmn.io camunda-modeler


【解决方案1】:

我找到了这个问题的原因。似乎我使用的 bpmn-js 版本与项目依赖于将 bpmn 解析为 xml 的 camunda-moddle 版本不完全兼容。解决方案是一次恢复 bpmn-js 一个版本,直到我找到一个兼容并且没有任何意外属性被 camunda-moddle 错误处理的版本。

【讨论】:

  • 这是否意味着升级到 0.26.6 会导致构建不稳定?
  • 如果您使用的是 camunda-bpmn-moddle,似乎就是这种情况。我还尝试了 0.27 版,结果相同。我最终使用的是 0.20 版。
  • 哦,好的。你会在 github 上打开一个问题并描述你的问题吗?
  • 绝对!感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 2021-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多