xml schema原有文档基础上嵌入自定义xml属性

因工作需要实现公司自研的工作流bpmn规范化。研发过程总发现需要学习xml schema来自定义本公司自身产品独有的属性。参考activity和camunda两款工作流产品。现做几点总结:

  • 1.xml约束分dtd和schema两种,dtd简单容易上手,但是工作中却基本不用,而是使用复杂的schema(支持更丰富和更复杂的数据类型)。网上的博客关于schema的基本只是入门(浅尝辄止)难以符合真正开发需要。不过在菜鸟教程和w3c中都有完整的教程和使用案例,需要学习或者使用schema建议直接看这些教程而不是只看博客。链接一:https://www.runoob.com/schema/schema-tutorial.html链接二:https://www.w3school.com.cn/schema/index.asp
  • 2.关于schema中的命名空间,搜了一大圈感觉都没有一个靠谱或者易懂的讲解。最后我自己几次尝试后,给出以下解释,命名空间的属性和属性值都是可以随便自定义的,只要不和原有的重复既可以,多数是取自己公司的网站名,仅仅是一个标识作用而已。参考下面的Camunda xml的文件头部定义xmlns:camunda="http://camunda.org/schema/1.0/bpmn" ,这里的camunda可以改成任何不重复的字段,一般取自己产品的名字,这里的“http://camunda.org/schema/1.0/bpmn”也不需要是个网址,任何唯一标识都可以,你可以随意改成自己公司的网址也行,类似于一个声明,我是唯一的,跟你们bpmn:不一样,我也可以<camuda:..></camuda..> 写自己的属性。当然这里要和schema中的这个要一致。
<?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:dc="http://www.omg.org/spec/DD/20100524/DC"
 xmlns:di="http://www.omg.org/spec/DD/20100524/DI" 
 xmlns:camunda="http://camunda.org/schema/1.0/bpmn" 
 id="Definitions_0i8bey3" 
 targetNamespace="http://bpmn.io/schema/bpmn" 
 exporter="Camunda Modeler" exporterVersion="3.5.0">
  <bpmn:process id="Process_07f8iwl" name="你好" isExecutable="true" camunda:versionTag="1.1.1">
    <bpmn:startEvent id="StartEvent_1" name="开始">
      <bpmn:outgoing>SequenceFlow_14ixhwl</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:endEvent id="EndEvent_11e4ewc" name="结束">
      <bpmn:incoming>SequenceFlow_14ixhwl</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="SequenceFlow_14ixhwl" sourceRef="StartEvent_1" targetRef="EndEvent_11e4ewc" />
    <bpmn:manualTask id="Task_12xfq2y" />
    <bpmn:serviceTask id="Task_1cic714" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_07f8iwl">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="179" y="249" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="186" y="285" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="EndEvent_11e4ewc_di" bpmnElement="EndEvent_11e4ewc">
        <dc:Bounds x="452" y="249" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="459" y="285" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_14ixhwl_di" bpmnElement="SequenceFlow_14ixhwl">
        <di:waypoint x="215" y="267" />
        <di:waypoint x="452" y="267" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="ManualTask_06n8x6n_di" bpmnElement="Task_12xfq2y">
        <dc:Bounds x="240" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="ServiceTask_03he7pw_di" bpmnElement="Task_1cic714">
        <dc:Bounds x="490" y="90" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

  • 3.schema教程中的复杂类型和anyattribute章节要细看。尤其是anyattribute可以解决xml在原有的属性中嵌入一些新属性。

  • 4.关于bpmn规范化,bpmn中提供了<bpmn:extensionElements>元素可供各厂家拓展使用。
  • 5.关于xml解析常使用dom4j,用xpath解析也很方便,注意使用xpath的时候不仅需要引入dom4j还要引入jaxen不然运行会报错。
dependencies>


    <dependency>

        <groupId>dom4j</groupId>

        <artifactId>dom4j</artifactId>

        <version>1.6.1</version>

    </dependency>

<!-- https://mvnrepository.com/artifact/jaxen/jaxen -->



    <dependency>

        <groupId>jaxen</groupId>

        <artifactId>jaxen</artifactId>

        <version>1.1.1</version>

    </dependency>

</dependencies>

如有xml、schema约束不懂得地方欢迎留言探讨,需要参考bpmn2.0规范化demo项目的同学也可以联系我,后面开源。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Knight_Ren

资源不易,打赏随意

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值