一、DOM与SAX的区别
DOM(Document Object Model,文档对象模型):是W3C定义的标记语言的标准操作,
在DOM操作之中需要将所有的标记转换为DOM树进行处理,并且使用DOM可以实现数据的读取与修改功能。
SAX(simple API for XML,简单XML解析工具)是一种XML解析的替代方法。相比于DOM,SAX是一种速度更快,更有效的方法。它逐行扫描文档,一边扫描一边解析。而且相比于DOM,SAX可以在解析文档的任意时刻停止解析,但任何事物都有其相反的一面,对于SAX来说就是操作复杂。本身适合于读取大型数据,但是SAX不允许修改文档。
二、常用API
dom4j的API接口 | 描述 |
---|---|
Node | dom4j树中所有节点接口 |
Branch | 代表能包含子节点的节点 |
Element | XML元素 |
Document | XML文档 |
Attribute | XML元素属性 |
DocumentType | XML文档中COCTYPE声明 |
ProcessingInstruction | XML文档中的处理指令 |
CharcterData | 文本元素的父接口 |
CDATA | XML文档中的CDATA段 |
Text | XML文档中的文本内容 |
Comment | XML文档注释内容 |
1、DocumentHelper创建工具类
在DOM操作中如果要想使用Document,需要DocumentBuilderFactory与DocumentBuilder两个类
但是这两个类的使用太麻烦了,所以DOM4J提供了一个org.dom4j.DocumentHelper。
主要方法:
(1)创建文档对象:public static Document createDocument()
(2)创建文档同时设置根元素:public static Document createDocument(Element rootElement)
(3)创建元素:public static Element createElement(java.lang.String name)
(4)创建属性:public static Attribute createAttribute(Element owner,QName qname,java.lang.String value)
2、Document操作接口
org.dom4j.Document(是Branch子接口,Branch是Node的子接口)
在整个XML文件里面一定会存在有Document的概念,在这个接口里面定义有如下方法:
(1)取得根元素:public Element getRootElement()
(2)设置根元素:public void setRootElement(Element rootElement)
(3)设置XML文件编码:public void setXMLEncoding(java.lang.String encoding)
3、org.dom4j.Branch接口的方法
(1)增加节点对象:public void add(Node node)
(2)增加元素:public Element addElement(java.lang.String name)
(3)取得指定索引的节点:public Node node(int index) throws java.lang.IndexOutOfBoundsException
(4)节点个数:public int nodeCount()
(5)删除节点:public boolean remove(Node node)
4、org.dom4j.Node接口的方法
(1)取得父节点:public Element getParent()
(2)取得节点的内容:public java.lang.String getText()
(3)设置节点的内容:public void setText(java.lang.String text)
(4)获取node名字:getName
(5) 获取node类型常量值:getNodeType
(6)获取node类型名称:getNodeTypeName
5、 org.dom4j.Element接口的方法
(1)返回该元素的属性列表:attributes
(2)根据传入的属性名获取属性值:attributeValue
(3)返回包含子元素的迭代器:elementIterator
(4)返回包含子元素的列表:element
Element类
getQName() | 元素的QName对象 |
getNamespace() | 元素所属的Namespace对象 |
getNamespacePrefix() | 元素所属的Namespace对象的prefix |
getNamespaceURI() | 元素所属的Namespace对象的URI |
getName() | 返回元素(属性)的本地名 |
getQualifiedName() | 返回元素(属性)的限定名 |
getText() | 元素所含有的text内容,如果内容为空则返回一个空字符串而不是null |
getTextTrim() | 元素所含有的text内容,其中连续的空格被转化为单个空格,该方法不会返回null |
attributeIterator() | 元素属性的iterator,其中每个元素都是Attribute对象 |
attributeValue() | 元素的某个指定属性所含的值 |
elementIterator() | 元素的子元素的iterator,其中每个元素都是Element对象 |
element() | 元素的某个指定(qualified name或者local name)的子元素 |
elementText() | 元素的某个指定(qualified name或者local name)的子元素中的text信息 |
getParent | 元素的父元素 |
getPath() | 元素的XPath表达式,其中父元素的qualified name和子元素的qualified name之间使用"/"分隔 |
isTextOnly() | 是否该元素只含有text或是空元素 |
isRootElement() | 是否该元素是XML树的根节点 |
6、 org.dom4j.Attribute接口的方法
(1)获取属性名:getName
(2)获取属性值:getValue
7、数据格式化输出类:org.dom4j.io.OutputFormat
(1)紧凑型输出:public static OutputFormat createCompactFormat()
(2)漂亮的输出:public static OutputFormat createPrettyPrint()
(3)设置输出编码:public void setEncoding(java.lang.String encoding)
8、输出数据类:org.dom4j.io.XMLWriter
(1)构造方法:public XMLWriter(OutputFormat format) throws java.io.UnsupportedEncodingException
(2)内容输出:public void write(Document doc) throws java.io.IOException
三、案例
1、需求
(1)表头声明添加插件
xmlns:flowable="http://flowable.org/bpmn"
(2)服务任务(serviceTask)添加参数指定class(方法类的全路径):
flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler"
(3)添加元素,用于区分执行不同的操作
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"文件情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
2、原始XML文件
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bpmn2="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"
id="diagram_Process_1663234442926" targetNamespace="http://activiti.org/bpmn">
<bpmn2:process id="task" name="情报测试原始模板" isExecutable="true">
<bpmn2:startEvent id="Event_1d982f4">
<bpmn2:outgoing>Flow_1a8zt74</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:exclusiveGateway id="Gateway_1kb5vve">
<bpmn2:incoming>Flow_1a8zt74</bpmn2:incoming>
<bpmn2:outgoing>Flow_1geuark</bpmn2:outgoing>
<bpmn2:outgoing>Flow_1asqvju</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:sequenceFlow id="Flow_1a8zt74" sourceRef="Event_1d982f4" targetRef="Gateway_1kb5vve"/>
<bpmn2:sequenceFlow id="Flow_1geuark" sourceRef="Gateway_1kb5vve" targetRef="Activity_083ibjy">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${condition == 'IP'}
</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_1asqvju" sourceRef="Gateway_1kb5vve" targetRef="Activity_0579ovv">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${condition == 'FILE'}
</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:serviceTask id="Activity_083ibjy" name="IP情报">
<bpmn2:incoming>Flow_1geuark</bpmn2:incoming>
<bpmn2:outgoing>Flow_0bopkdm</bpmn2:outgoing>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0579ovv" name="文件情报">
<bpmn2:incoming>Flow_1asqvju</bpmn2:incoming>
<bpmn2:outgoing>Flow_1ed3r0x</bpmn2:outgoing>
</bpmn2:serviceTask>
<bpmn2:exclusiveGateway id="Gateway_1dwwf2j">
<bpmn2:incoming>Flow_0bopkdm</bpmn2:incoming>
<bpmn2:outgoing>Flow_11k8mfp</bpmn2:outgoing>
<bpmn2:outgoing>Flow_0iibvpb</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:sequenceFlow id="Flow_0bopkdm" sourceRef="Activity_083ibjy" targetRef="Gateway_1dwwf2j"/>
<bpmn2:sequenceFlow id="Flow_11k8mfp" name="IP恶意" sourceRef="Gateway_1dwwf2j" targetRef="Activity_0n01hsi">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'Y'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_0iibvpb" name="IP不恶意" sourceRef="Gateway_1dwwf2j" targetRef="Activity_0ajbbgw">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'N'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:exclusiveGateway id="Gateway_06xn02q">
<bpmn2:incoming>Flow_1ed3r0x</bpmn2:incoming>
<bpmn2:outgoing>Flow_0j813j5</bpmn2:outgoing>
<bpmn2:outgoing>Flow_13w7ghd</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:sequenceFlow id="Flow_1ed3r0x" sourceRef="Activity_0579ovv" targetRef="Gateway_06xn02q"/>
<bpmn2:sequenceFlow id="Flow_0j813j5" name="文件可疑" sourceRef="Gateway_06xn02q" targetRef="Activity_0ysr2o8">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'Y'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_1ugqxth" sourceRef="Activity_0n01hsi" targetRef="Activity_0i27q99"/>
<bpmn2:sequenceFlow id="Flow_0uospyb" sourceRef="Activity_0ajbbgw" targetRef="Activity_0dlnxde"/>
<bpmn2:endEvent id="Event_1ucrxbu">
<bpmn2:incoming>Flow_0vzshkg</bpmn2:incoming>
<bpmn2:incoming>Flow_0v2j0ig</bpmn2:incoming>
<bpmn2:incoming>Flow_0frjzww</bpmn2:incoming>
<bpmn2:incoming>Flow_13w7ghd</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="Flow_0vzshkg" sourceRef="Activity_0i27q99" targetRef="Event_1ucrxbu"/>
<bpmn2:sequenceFlow id="Flow_0v2j0ig" sourceRef="Activity_0dlnxde" targetRef="Event_1ucrxbu"/>
<bpmn2:serviceTask id="Activity_0ysr2o8" name="隔离文件">
<bpmn2:incoming>Flow_0j813j5</bpmn2:incoming>
<bpmn2:outgoing>Flow_0frjzww</bpmn2:outgoing>
</bpmn2:serviceTask>
<bpmn2:sequenceFlow id="Flow_0frjzww" sourceRef="Activity_0ysr2o8" targetRef="Event_1ucrxbu"/>
<bpmn2:sequenceFlow id="Flow_13w7ghd" name="文件不可疑" sourceRef="Gateway_06xn02q" targetRef="Event_1ucrxbu">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'N'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:serviceTask id="Activity_0ajbbgw" name="策略">
<bpmn2:incoming>Flow_0iibvpb</bpmn2:incoming>
<bpmn2:outgoing>Flow_0uospyb</bpmn2:outgoing>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0n01hsi" name="IP阻断">
<bpmn2:incoming>Flow_11k8mfp</bpmn2:incoming>
<bpmn2:outgoing>Flow_1ugqxth</bpmn2:outgoing>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0i27q99" name="创建工单">
<bpmn2:incoming>Flow_1ugqxth</bpmn2:incoming>
<bpmn2:outgoing>Flow_0vzshkg</bpmn2:outgoing>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0dlnxde" name="发送邮件">
<bpmn2:incoming>Flow_0uospyb</bpmn2:incoming>
<bpmn2:outgoing>Flow_0v2j0ig</bpmn2:outgoing>
</bpmn2:serviceTask>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="task_di" bpmnElement="task">
<bpmndi:BPMNEdge id="Flow_13w7ghd_di" bpmnElement="Flow_13w7ghd">
<di:waypoint x="550" y="375"/>
<di:waypoint x="550" y="510"/>
<di:waypoint x="1060" y="510"/>
<di:waypoint x="1060" y="188"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="778" y="492" width="55" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0frjzww_di" bpmnElement="Flow_0frjzww">
<di:waypoint x="810" y="350"/>
<di:waypoint x="1060" y="350"/>
<di:waypoint x="1060" y="188"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0v2j0ig_di" bpmnElement="Flow_0v2j0ig">
<di:waypoint x="910" y="220"/>
<di:waypoint x="976" y="220"/>
<di:waypoint x="976" y="170"/>
<di:waypoint x="1042" y="170"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0vzshkg_di" bpmnElement="Flow_0vzshkg">
<di:waypoint x="910" y="-20"/>
<di:waypoint x="976" y="-20"/>
<di:waypoint x="976" y="170"/>
<di:waypoint x="1042" y="170"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0uospyb_di" bpmnElement="Flow_0uospyb">
<di:waypoint x="740" y="220"/>
<di:waypoint x="810" y="220"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ugqxth_di" bpmnElement="Flow_1ugqxth">
<di:waypoint x="730" y="-20"/>
<di:waypoint x="810" y="-20"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0j813j5_di" bpmnElement="Flow_0j813j5">
<di:waypoint x="575" y="350"/>
<di:waypoint x="710" y="350"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="622" y="332" width="44" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ed3r0x_di" bpmnElement="Flow_1ed3r0x">
<di:waypoint x="460" y="350"/>
<di:waypoint x="525" y="350"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0iibvpb_di" bpmnElement="Flow_0iibvpb">
<di:waypoint x="550" y="135"/>
<di:waypoint x="550" y="220"/>
<di:waypoint x="640" y="220"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="557" y="175" width="45" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_11k8mfp_di" bpmnElement="Flow_11k8mfp">
<di:waypoint x="550" y="85"/>
<di:waypoint x="550" y="-20"/>
<di:waypoint x="630" y="-20"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="563" y="30" width="34" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0bopkdm_di" bpmnElement="Flow_0bopkdm">
<di:waypoint x="460" y="110"/>
<di:waypoint x="525" y="110"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1asqvju_di" bpmnElement="Flow_1asqvju">
<di:waypoint x="270" y="265"/>
<di:waypoint x="270" y="350"/>
<di:waypoint x="360" y="350"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1geuark_di" bpmnElement="Flow_1geuark">
<di:waypoint x="270" y="215"/>
<di:waypoint x="270" y="110"/>
<di:waypoint x="360" y="110"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1a8zt74_di" bpmnElement="Flow_1a8zt74">
<di:waypoint x="188" y="240"/>
<di:waypoint x="245" y="240"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_1d982f4_di" bpmnElement="Event_1d982f4">
<dc:Bounds x="152" y="222" width="36" height="36"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1kb5vve_di" bpmnElement="Gateway_1kb5vve" isMarkerVisible="true">
<dc:Bounds x="245" y="215" width="50" height="50"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0n3lstu_di" bpmnElement="Activity_083ibjy">
<dc:Bounds x="360" y="70" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1u8478q_di" bpmnElement="Activity_0579ovv">
<dc:Bounds x="360" y="310" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1dwwf2j_di" bpmnElement="Gateway_1dwwf2j" isMarkerVisible="true">
<dc:Bounds x="525" y="85" width="50" height="50"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_06xn02q_di" bpmnElement="Gateway_06xn02q" isMarkerVisible="true">
<dc:Bounds x="525" y="325" width="50" height="50"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ucrxbu_di" bpmnElement="Event_1ucrxbu">
<dc:Bounds x="1042" y="152" width="36" height="36"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ipps3t_di" bpmnElement="Activity_0ysr2o8">
<dc:Bounds x="710" y="310" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0073q7h_di" bpmnElement="Activity_0ajbbgw">
<dc:Bounds x="640" y="180" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0nx7c34_di" bpmnElement="Activity_0n01hsi">
<dc:Bounds x="630" y="-60" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0alrvbz_di" bpmnElement="Activity_0i27q99">
<dc:Bounds x="810" y="-60" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1mgp02f_di" bpmnElement="Activity_0dlnxde">
<dc:Bounds x="810" y="180" width="100" height="80"/>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
3、dom4j依赖
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.1</version>
</dependency>
4、具体实现
添加之后,再次修改xml文件时,需判断标签存在不存在,若存在则不再添加。
public static void main(String[] args) {
// xml字符串
String bpmnXmlas = "原始XML内容";
try {
// 解析XML字符串,得到document对象
Document document = DocumentHelper.parseText(bpmnXmlas);
// 获取根元素
Element rootOri = document.getRootElement();
// 添加属性
List<Namespace> namespaces = rootOri.declaredNamespaces();
List<String> rootNamespaces = new ArrayList<>();
for (Namespace namespace : namespaces) {
rootNamespaces.add(namespace.getPrefix());
}
if (!namespaces.contains("flowable")) {
rootOri.addAttribute("xmlns:flowable", "http://flowable.org/bpmn");
}
// 获取添加插件后的Document
// 需先添加xmlns:flowable插件,否则会报错No such namespace prefix: flowable is in scope on: org.dom4j.tree.DefaultEle......
Document documentUp = DocumentHelper.parseText(document.asXML());
Element rootElement = documentUp.getRootElement();
Iterator<Element> elementIterator = rootElement.elementIterator();
while (elementIterator.hasNext()) {
Element next = elementIterator.next();
if (next.getQualifiedName().equals("bpmn2:process")) {
System.out.println("bpmn2:process-------------" + next.getQualifiedName());
Iterator<Element> childElement = next.elementIterator();
while (childElement.hasNext()) {
Element itemEle = childElement.next();
if (itemEle.getQualifiedName().equals("bpmn2:serviceTask")) {
System.out.println("bpmn2:serviceTask------------" + itemEle.getQualifiedName());
List<Attribute> attributes = itemEle.attributes();
List<String> names = new ArrayList<>();
for (Attribute attribute : attributes) {
names.add(attribute.getQualifiedName());
}
// 存在则不添加
if (!names.contains("flowable:class")) {
itemEle.addAttribute("flowable:class", "com.lc.mono.shop.listener.ManagerTaskFunctionHandler");
}
// 获取子节点名称
Iterator<Node> nodeIterator = itemEle.nodeIterator();
List<String> nodeNames = new ArrayList<>();
while (nodeIterator.hasNext()) {
Node node = nodeIterator.next();
nodeNames.add(node.getName());
System.out.println("node.getName------------" + node.getName());
}
// 存在则不添加
if (!nodeNames.contains("extensionElements")) {
// 在bpmn2:serviceTask下,添加字节的
Element extensionElements1 = null;
extensionElements1 = itemEle.addElement("bpmn2:extensionElements");
Element extensionElements2 = null;
extensionElements2 = extensionElements1.addElement("flowable:field");
extensionElements2.addAttribute("name", "params");
Element extensionElements3 = null;
extensionElements3 = extensionElements2.addElement("flowable:string");
extensionElements3.setText("{\"type\":\"console\",\"string\":\"IP情报\"}");
}
}
}
}
}
// 1.声明文件名称
String fileName = "xml_test";
// 4、格式化模板
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
// 5、生成xml文件
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, format);
writer.write(documentUp);
writer.close();
// 将文件输出到D盘
FileOutputStream fos = new FileOutputStream("D:/" + fileName + ".xml");
fos.write(out.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
}
修改后的XML文件
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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:flowable="http://flowable.org/bpmn" id="diagram_Process_1663234442926" targetNamespace="http://activiti.org/bpmn">
<bpmn2:process id="task" name="情报测试原始模板" isExecutable="true">
<bpmn2:startEvent id="Event_1d982f4">
<bpmn2:outgoing>Flow_1a8zt74</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:exclusiveGateway id="Gateway_1kb5vve">
<bpmn2:incoming>Flow_1a8zt74</bpmn2:incoming>
<bpmn2:outgoing>Flow_1geuark</bpmn2:outgoing>
<bpmn2:outgoing>Flow_1asqvju</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:sequenceFlow id="Flow_1a8zt74" sourceRef="Event_1d982f4" targetRef="Gateway_1kb5vve"/>
<bpmn2:sequenceFlow id="Flow_1geuark" sourceRef="Gateway_1kb5vve" targetRef="Activity_083ibjy">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${condition == 'IP'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_1asqvju" sourceRef="Gateway_1kb5vve" targetRef="Activity_0579ovv">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${condition == 'FILE'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:serviceTask id="Activity_083ibjy" name="IP情报" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:incoming>Flow_1geuark</bpmn2:incoming>
<bpmn2:outgoing>Flow_0bopkdm</bpmn2:outgoing>
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"IP情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0579ovv" name="文件情报" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:incoming>Flow_1asqvju</bpmn2:incoming>
<bpmn2:outgoing>Flow_1ed3r0x</bpmn2:outgoing>
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"IP情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
</bpmn2:serviceTask>
<bpmn2:exclusiveGateway id="Gateway_1dwwf2j">
<bpmn2:incoming>Flow_0bopkdm</bpmn2:incoming>
<bpmn2:outgoing>Flow_11k8mfp</bpmn2:outgoing>
<bpmn2:outgoing>Flow_0iibvpb</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:sequenceFlow id="Flow_0bopkdm" sourceRef="Activity_083ibjy" targetRef="Gateway_1dwwf2j"/>
<bpmn2:sequenceFlow id="Flow_11k8mfp" name="IP恶意" sourceRef="Gateway_1dwwf2j" targetRef="Activity_0n01hsi">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'Y'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_0iibvpb" name="IP不恶意" sourceRef="Gateway_1dwwf2j" targetRef="Activity_0ajbbgw">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'N'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:exclusiveGateway id="Gateway_06xn02q">
<bpmn2:incoming>Flow_1ed3r0x</bpmn2:incoming>
<bpmn2:outgoing>Flow_0j813j5</bpmn2:outgoing>
<bpmn2:outgoing>Flow_13w7ghd</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:sequenceFlow id="Flow_1ed3r0x" sourceRef="Activity_0579ovv" targetRef="Gateway_06xn02q"/>
<bpmn2:sequenceFlow id="Flow_0j813j5" name="文件可疑" sourceRef="Gateway_06xn02q" targetRef="Activity_0ysr2o8">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'Y'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_1ugqxth" sourceRef="Activity_0n01hsi" targetRef="Activity_0i27q99"/>
<bpmn2:sequenceFlow id="Flow_0uospyb" sourceRef="Activity_0ajbbgw" targetRef="Activity_0dlnxde"/>
<bpmn2:endEvent id="Event_1ucrxbu">
<bpmn2:incoming>Flow_0vzshkg</bpmn2:incoming>
<bpmn2:incoming>Flow_0v2j0ig</bpmn2:incoming>
<bpmn2:incoming>Flow_0frjzww</bpmn2:incoming>
<bpmn2:incoming>Flow_13w7ghd</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="Flow_0vzshkg" sourceRef="Activity_0i27q99" targetRef="Event_1ucrxbu"/>
<bpmn2:sequenceFlow id="Flow_0v2j0ig" sourceRef="Activity_0dlnxde" targetRef="Event_1ucrxbu"/>
<bpmn2:serviceTask id="Activity_0ysr2o8" name="隔离文件" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:incoming>Flow_0j813j5</bpmn2:incoming>
<bpmn2:outgoing>Flow_0frjzww</bpmn2:outgoing>
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"IP情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
</bpmn2:serviceTask>
<bpmn2:sequenceFlow id="Flow_0frjzww" sourceRef="Activity_0ysr2o8" targetRef="Event_1ucrxbu"/>
<bpmn2:sequenceFlow id="Flow_13w7ghd" name="文件不可疑" sourceRef="Gateway_06xn02q" targetRef="Event_1ucrxbu">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${select == 'N'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:serviceTask id="Activity_0ajbbgw" name="策略" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:incoming>Flow_0iibvpb</bpmn2:incoming>
<bpmn2:outgoing>Flow_0uospyb</bpmn2:outgoing>
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"IP情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0n01hsi" name="IP阻断" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:incoming>Flow_11k8mfp</bpmn2:incoming>
<bpmn2:outgoing>Flow_1ugqxth</bpmn2:outgoing>
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"IP情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0i27q99" name="创建工单" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:incoming>Flow_1ugqxth</bpmn2:incoming>
<bpmn2:outgoing>Flow_0vzshkg</bpmn2:outgoing>
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"IP情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
</bpmn2:serviceTask>
<bpmn2:serviceTask id="Activity_0dlnxde" name="发送邮件" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:incoming>Flow_0uospyb</bpmn2:incoming>
<bpmn2:outgoing>Flow_0v2j0ig</bpmn2:outgoing>
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:string>{"type":"console","string":"IP情报"}</flowable:string>
</flowable:field>
</bpmn2:extensionElements>
</bpmn2:serviceTask>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="task_di" bpmnElement="task">
<bpmndi:BPMNEdge id="Flow_13w7ghd_di" bpmnElement="Flow_13w7ghd">
<di:waypoint x="550" y="375"/>
<di:waypoint x="550" y="510"/>
<di:waypoint x="1060" y="510"/>
<di:waypoint x="1060" y="188"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="778" y="492" width="55" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0frjzww_di" bpmnElement="Flow_0frjzww">
<di:waypoint x="810" y="350"/>
<di:waypoint x="1060" y="350"/>
<di:waypoint x="1060" y="188"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0v2j0ig_di" bpmnElement="Flow_0v2j0ig">
<di:waypoint x="910" y="220"/>
<di:waypoint x="976" y="220"/>
<di:waypoint x="976" y="170"/>
<di:waypoint x="1042" y="170"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0vzshkg_di" bpmnElement="Flow_0vzshkg">
<di:waypoint x="910" y="-20"/>
<di:waypoint x="976" y="-20"/>
<di:waypoint x="976" y="170"/>
<di:waypoint x="1042" y="170"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0uospyb_di" bpmnElement="Flow_0uospyb">
<di:waypoint x="740" y="220"/>
<di:waypoint x="810" y="220"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ugqxth_di" bpmnElement="Flow_1ugqxth">
<di:waypoint x="730" y="-20"/>
<di:waypoint x="810" y="-20"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0j813j5_di" bpmnElement="Flow_0j813j5">
<di:waypoint x="575" y="350"/>
<di:waypoint x="710" y="350"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="622" y="332" width="44" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ed3r0x_di" bpmnElement="Flow_1ed3r0x">
<di:waypoint x="460" y="350"/>
<di:waypoint x="525" y="350"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0iibvpb_di" bpmnElement="Flow_0iibvpb">
<di:waypoint x="550" y="135"/>
<di:waypoint x="550" y="220"/>
<di:waypoint x="640" y="220"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="557" y="175" width="45" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_11k8mfp_di" bpmnElement="Flow_11k8mfp">
<di:waypoint x="550" y="85"/>
<di:waypoint x="550" y="-20"/>
<di:waypoint x="630" y="-20"/>
<bpmndi:BPMNLabel>
<dc:Bounds x="563" y="30" width="34" height="14"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0bopkdm_di" bpmnElement="Flow_0bopkdm">
<di:waypoint x="460" y="110"/>
<di:waypoint x="525" y="110"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1asqvju_di" bpmnElement="Flow_1asqvju">
<di:waypoint x="270" y="265"/>
<di:waypoint x="270" y="350"/>
<di:waypoint x="360" y="350"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1geuark_di" bpmnElement="Flow_1geuark">
<di:waypoint x="270" y="215"/>
<di:waypoint x="270" y="110"/>
<di:waypoint x="360" y="110"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1a8zt74_di" bpmnElement="Flow_1a8zt74">
<di:waypoint x="188" y="240"/>
<di:waypoint x="245" y="240"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_1d982f4_di" bpmnElement="Event_1d982f4">
<dc:Bounds x="152" y="222" width="36" height="36"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1kb5vve_di" bpmnElement="Gateway_1kb5vve" isMarkerVisible="true">
<dc:Bounds x="245" y="215" width="50" height="50"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0n3lstu_di" bpmnElement="Activity_083ibjy">
<dc:Bounds x="360" y="70" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1u8478q_di" bpmnElement="Activity_0579ovv">
<dc:Bounds x="360" y="310" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1dwwf2j_di" bpmnElement="Gateway_1dwwf2j" isMarkerVisible="true">
<dc:Bounds x="525" y="85" width="50" height="50"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_06xn02q_di" bpmnElement="Gateway_06xn02q" isMarkerVisible="true">
<dc:Bounds x="525" y="325" width="50" height="50"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ucrxbu_di" bpmnElement="Event_1ucrxbu">
<dc:Bounds x="1042" y="152" width="36" height="36"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ipps3t_di" bpmnElement="Activity_0ysr2o8">
<dc:Bounds x="710" y="310" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0073q7h_di" bpmnElement="Activity_0ajbbgw">
<dc:Bounds x="640" y="180" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0nx7c34_di" bpmnElement="Activity_0n01hsi">
<dc:Bounds x="630" y="-60" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0alrvbz_di" bpmnElement="Activity_0i27q99">
<dc:Bounds x="810" y="-60" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1mgp02f_di" bpmnElement="Activity_0dlnxde">
<dc:Bounds x="810" y="180" width="100" height="80"/>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
5、对比
后期可根据需求修改每个serviceTask中的内容
6、获取父标签内容并删除标签
public static void main(String[] args) {
// xml字符串
String bpmnXmlas = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<bpmn2:definitions xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xmlns:bpmn2=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"\n" +
" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"\n" +
" xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"\n" +
" xmlns:flowable=\"http://flowable.org/bpmn\" id=\"diagram_Process_1663234442926\"\n" +
" targetNamespace=\"http://activiti.org/bpmn\">\n" +
" <bpmn2:process id=\"task\" name=\"情报测试原始模板\" isExecutable=\"true\">\n" +
" <bpmn2:startEvent id=\"Event_1d982f4\">\n" +
" <bpmn2:outgoing>Flow_1a8zt74</bpmn2:outgoing>\n" +
" </bpmn2:startEvent>\n" +
" <bpmn2:exclusiveGateway id=\"Gateway_1kb5vve\">\n" +
" <bpmn2:incoming>Flow_1a8zt74</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_1geuark</bpmn2:outgoing>\n" +
" <bpmn2:outgoing>Flow_1asqvju</bpmn2:outgoing>\n" +
" </bpmn2:exclusiveGateway>\n" +
" <bpmn2:sequenceFlow id=\"Flow_1a8zt74\" sourceRef=\"Event_1d982f4\" targetRef=\"Gateway_1kb5vve\"/>\n" +
" <bpmn2:sequenceFlow id=\"Flow_1geuark\" sourceRef=\"Gateway_1kb5vve\" targetRef=\"Activity_083ibjy\">\n" +
" <bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${condition == 'IP'}\n" +
" </bpmn2:conditionExpression>\n" +
" </bpmn2:sequenceFlow>\n" +
" <bpmn2:sequenceFlow id=\"Flow_1asqvju\" sourceRef=\"Gateway_1kb5vve\" targetRef=\"Activity_0579ovv\">\n" +
" <bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${condition == 'FILE'}\n" +
" </bpmn2:conditionExpression>\n" +
" </bpmn2:sequenceFlow>\n" +
" <bpmn2:serviceTask id=\"Activity_083ibjy\" name=\"IP情报\">\n" +
" <bpmn2:extensionElements>\n" +
" <flowable:executionListener class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\" event=\"start\">\n" +
" <flowable:field name=\"params\">\n" +
" <flowable:string>{\"type\":\"console\",\"value\":\"IP\"}</flowable:string>\n" +
" </flowable:field>\n" +
" </flowable:executionListener>\n" +
" </bpmn2:extensionElements>\n" +
" <bpmn2:incoming>Flow_1geuark</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_0bopkdm</bpmn2:outgoing>\n" +
" </bpmn2:serviceTask>\n" +
" <bpmn2:serviceTask id=\"Activity_0579ovv\" name=\"文件情报\">\n" +
" <bpmn2:incoming>Flow_1asqvju</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_1ed3r0x</bpmn2:outgoing>\n" +
" </bpmn2:serviceTask>\n" +
" <bpmn2:exclusiveGateway id=\"Gateway_1dwwf2j\">\n" +
" <bpmn2:incoming>Flow_0bopkdm</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_11k8mfp</bpmn2:outgoing>\n" +
" <bpmn2:outgoing>Flow_0iibvpb</bpmn2:outgoing>\n" +
" </bpmn2:exclusiveGateway>\n" +
" <bpmn2:sequenceFlow id=\"Flow_0bopkdm\" sourceRef=\"Activity_083ibjy\" targetRef=\"Gateway_1dwwf2j\"/>\n" +
" <bpmn2:sequenceFlow id=\"Flow_11k8mfp\" name=\"IP恶意\" sourceRef=\"Gateway_1dwwf2j\" targetRef=\"Activity_0n01hsi\">\n" +
" <bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'Y'}</bpmn2:conditionExpression>\n" +
" </bpmn2:sequenceFlow>\n" +
" <bpmn2:sequenceFlow id=\"Flow_0iibvpb\" name=\"IP不恶意\" sourceRef=\"Gateway_1dwwf2j\" targetRef=\"Activity_0ajbbgw\">\n" +
" <bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'N'}</bpmn2:conditionExpression>\n" +
" </bpmn2:sequenceFlow>\n" +
" <bpmn2:exclusiveGateway id=\"Gateway_06xn02q\">\n" +
" <bpmn2:incoming>Flow_1ed3r0x</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_0j813j5</bpmn2:outgoing>\n" +
" <bpmn2:outgoing>Flow_13w7ghd</bpmn2:outgoing>\n" +
" </bpmn2:exclusiveGateway>\n" +
" <bpmn2:sequenceFlow id=\"Flow_1ed3r0x\" sourceRef=\"Activity_0579ovv\" targetRef=\"Gateway_06xn02q\"/>\n" +
" <bpmn2:sequenceFlow id=\"Flow_0j813j5\" name=\"文件可疑\" sourceRef=\"Gateway_06xn02q\" targetRef=\"Activity_0ysr2o8\">\n" +
" <bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'Y'}</bpmn2:conditionExpression>\n" +
" </bpmn2:sequenceFlow>\n" +
" <bpmn2:sequenceFlow id=\"Flow_1ugqxth\" sourceRef=\"Activity_0n01hsi\" targetRef=\"Activity_0i27q99\"/>\n" +
" <bpmn2:sequenceFlow id=\"Flow_0uospyb\" sourceRef=\"Activity_0ajbbgw\" targetRef=\"Activity_0dlnxde\"/>\n" +
" <bpmn2:endEvent id=\"Event_1ucrxbu\">\n" +
" <bpmn2:incoming>Flow_0vzshkg</bpmn2:incoming>\n" +
" <bpmn2:incoming>Flow_0v2j0ig</bpmn2:incoming>\n" +
" <bpmn2:incoming>Flow_0frjzww</bpmn2:incoming>\n" +
" <bpmn2:incoming>Flow_13w7ghd</bpmn2:incoming>\n" +
" </bpmn2:endEvent>\n" +
" <bpmn2:sequenceFlow id=\"Flow_0vzshkg\" sourceRef=\"Activity_0i27q99\" targetRef=\"Event_1ucrxbu\"/>\n" +
" <bpmn2:sequenceFlow id=\"Flow_0v2j0ig\" sourceRef=\"Activity_0dlnxde\" targetRef=\"Event_1ucrxbu\"/>\n" +
" <bpmn2:serviceTask id=\"Activity_0ysr2o8\" name=\"隔离文件\">\n" +
" <bpmn2:incoming>Flow_0j813j5</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_0frjzww</bpmn2:outgoing>\n" +
" </bpmn2:serviceTask>\n" +
" <bpmn2:sequenceFlow id=\"Flow_0frjzww\" sourceRef=\"Activity_0ysr2o8\" targetRef=\"Event_1ucrxbu\"/>\n" +
" <bpmn2:sequenceFlow id=\"Flow_13w7ghd\" name=\"文件不可疑\" sourceRef=\"Gateway_06xn02q\" targetRef=\"Event_1ucrxbu\">\n" +
" <bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'N'}</bpmn2:conditionExpression>\n" +
" </bpmn2:sequenceFlow>\n" +
" <bpmn2:serviceTask id=\"Activity_0ajbbgw\" name=\"策略\">\n" +
" <bpmn2:incoming>Flow_0iibvpb</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_0uospyb</bpmn2:outgoing>\n" +
" </bpmn2:serviceTask>\n" +
" <bpmn2:serviceTask id=\"Activity_0n01hsi\" name=\"IP阻断\">\n" +
" <bpmn2:incoming>Flow_11k8mfp</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_1ugqxth</bpmn2:outgoing>\n" +
" </bpmn2:serviceTask>\n" +
" <bpmn2:serviceTask id=\"Activity_0i27q99\" name=\"创建工单\">\n" +
" <bpmn2:incoming>Flow_1ugqxth</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_0vzshkg</bpmn2:outgoing>\n" +
" </bpmn2:serviceTask>\n" +
" <bpmn2:serviceTask id=\"Activity_0dlnxde\" name=\"发送邮件\">\n" +
" <bpmn2:incoming>Flow_0uospyb</bpmn2:incoming>\n" +
" <bpmn2:outgoing>Flow_0v2j0ig</bpmn2:outgoing>\n" +
" </bpmn2:serviceTask>\n" +
" </bpmn2:process>\n" +
" <bpmndi:BPMNDiagram id=\"BPMNDiagram_1\">\n" +
" <bpmndi:BPMNPlane id=\"task_di\" bpmnElement=\"task\">\n" +
" <bpmndi:BPMNEdge id=\"Flow_13w7ghd_di\" bpmnElement=\"Flow_13w7ghd\">\n" +
" <di:waypoint x=\"550\" y=\"375\"/>\n" +
" <di:waypoint x=\"550\" y=\"510\"/>\n" +
" <di:waypoint x=\"1060\" y=\"510\"/>\n" +
" <di:waypoint x=\"1060\" y=\"188\"/>\n" +
" <bpmndi:BPMNLabel>\n" +
" <dc:Bounds x=\"778\" y=\"492\" width=\"55\" height=\"14\"/>\n" +
" </bpmndi:BPMNLabel>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_0frjzww_di\" bpmnElement=\"Flow_0frjzww\">\n" +
" <di:waypoint x=\"810\" y=\"350\"/>\n" +
" <di:waypoint x=\"1060\" y=\"350\"/>\n" +
" <di:waypoint x=\"1060\" y=\"188\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_0v2j0ig_di\" bpmnElement=\"Flow_0v2j0ig\">\n" +
" <di:waypoint x=\"910\" y=\"220\"/>\n" +
" <di:waypoint x=\"976\" y=\"220\"/>\n" +
" <di:waypoint x=\"976\" y=\"170\"/>\n" +
" <di:waypoint x=\"1042\" y=\"170\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_0vzshkg_di\" bpmnElement=\"Flow_0vzshkg\">\n" +
" <di:waypoint x=\"910\" y=\"-20\"/>\n" +
" <di:waypoint x=\"976\" y=\"-20\"/>\n" +
" <di:waypoint x=\"976\" y=\"170\"/>\n" +
" <di:waypoint x=\"1042\" y=\"170\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_0uospyb_di\" bpmnElement=\"Flow_0uospyb\">\n" +
" <di:waypoint x=\"740\" y=\"220\"/>\n" +
" <di:waypoint x=\"810\" y=\"220\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_1ugqxth_di\" bpmnElement=\"Flow_1ugqxth\">\n" +
" <di:waypoint x=\"730\" y=\"-20\"/>\n" +
" <di:waypoint x=\"810\" y=\"-20\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_0j813j5_di\" bpmnElement=\"Flow_0j813j5\">\n" +
" <di:waypoint x=\"575\" y=\"350\"/>\n" +
" <di:waypoint x=\"710\" y=\"350\"/>\n" +
" <bpmndi:BPMNLabel>\n" +
" <dc:Bounds x=\"622\" y=\"332\" width=\"44\" height=\"14\"/>\n" +
" </bpmndi:BPMNLabel>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_1ed3r0x_di\" bpmnElement=\"Flow_1ed3r0x\">\n" +
" <di:waypoint x=\"460\" y=\"350\"/>\n" +
" <di:waypoint x=\"525\" y=\"350\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_0iibvpb_di\" bpmnElement=\"Flow_0iibvpb\">\n" +
" <di:waypoint x=\"550\" y=\"135\"/>\n" +
" <di:waypoint x=\"550\" y=\"220\"/>\n" +
" <di:waypoint x=\"640\" y=\"220\"/>\n" +
" <bpmndi:BPMNLabel>\n" +
" <dc:Bounds x=\"557\" y=\"175\" width=\"45\" height=\"14\"/>\n" +
" </bpmndi:BPMNLabel>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_11k8mfp_di\" bpmnElement=\"Flow_11k8mfp\">\n" +
" <di:waypoint x=\"550\" y=\"85\"/>\n" +
" <di:waypoint x=\"550\" y=\"-20\"/>\n" +
" <di:waypoint x=\"630\" y=\"-20\"/>\n" +
" <bpmndi:BPMNLabel>\n" +
" <dc:Bounds x=\"563\" y=\"30\" width=\"34\" height=\"14\"/>\n" +
" </bpmndi:BPMNLabel>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_0bopkdm_di\" bpmnElement=\"Flow_0bopkdm\">\n" +
" <di:waypoint x=\"460\" y=\"110\"/>\n" +
" <di:waypoint x=\"525\" y=\"110\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_1asqvju_di\" bpmnElement=\"Flow_1asqvju\">\n" +
" <di:waypoint x=\"270\" y=\"265\"/>\n" +
" <di:waypoint x=\"270\" y=\"350\"/>\n" +
" <di:waypoint x=\"360\" y=\"350\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_1geuark_di\" bpmnElement=\"Flow_1geuark\">\n" +
" <di:waypoint x=\"270\" y=\"215\"/>\n" +
" <di:waypoint x=\"270\" y=\"110\"/>\n" +
" <di:waypoint x=\"360\" y=\"110\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNEdge id=\"Flow_1a8zt74_di\" bpmnElement=\"Flow_1a8zt74\">\n" +
" <di:waypoint x=\"188\" y=\"240\"/>\n" +
" <di:waypoint x=\"245\" y=\"240\"/>\n" +
" </bpmndi:BPMNEdge>\n" +
" <bpmndi:BPMNShape id=\"Event_1d982f4_di\" bpmnElement=\"Event_1d982f4\">\n" +
" <dc:Bounds x=\"152\" y=\"222\" width=\"36\" height=\"36\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Gateway_1kb5vve_di\" bpmnElement=\"Gateway_1kb5vve\" isMarkerVisible=\"true\">\n" +
" <dc:Bounds x=\"245\" y=\"215\" width=\"50\" height=\"50\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Activity_0n3lstu_di\" bpmnElement=\"Activity_083ibjy\">\n" +
" <dc:Bounds x=\"360\" y=\"70\" width=\"100\" height=\"80\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Activity_1u8478q_di\" bpmnElement=\"Activity_0579ovv\">\n" +
" <dc:Bounds x=\"360\" y=\"310\" width=\"100\" height=\"80\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Gateway_1dwwf2j_di\" bpmnElement=\"Gateway_1dwwf2j\" isMarkerVisible=\"true\">\n" +
" <dc:Bounds x=\"525\" y=\"85\" width=\"50\" height=\"50\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Gateway_06xn02q_di\" bpmnElement=\"Gateway_06xn02q\" isMarkerVisible=\"true\">\n" +
" <dc:Bounds x=\"525\" y=\"325\" width=\"50\" height=\"50\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Event_1ucrxbu_di\" bpmnElement=\"Event_1ucrxbu\">\n" +
" <dc:Bounds x=\"1042\" y=\"152\" width=\"36\" height=\"36\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Activity_0ipps3t_di\" bpmnElement=\"Activity_0ysr2o8\">\n" +
" <dc:Bounds x=\"710\" y=\"310\" width=\"100\" height=\"80\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Activity_0073q7h_di\" bpmnElement=\"Activity_0ajbbgw\">\n" +
" <dc:Bounds x=\"640\" y=\"180\" width=\"100\" height=\"80\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Activity_0nx7c34_di\" bpmnElement=\"Activity_0n01hsi\">\n" +
" <dc:Bounds x=\"630\" y=\"-60\" width=\"100\" height=\"80\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Activity_0alrvbz_di\" bpmnElement=\"Activity_0i27q99\">\n" +
" <dc:Bounds x=\"810\" y=\"-60\" width=\"100\" height=\"80\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" <bpmndi:BPMNShape id=\"Activity_1mgp02f_di\" bpmnElement=\"Activity_0dlnxde\">\n" +
" <dc:Bounds x=\"810\" y=\"180\" width=\"100\" height=\"80\"/>\n" +
" </bpmndi:BPMNShape>\n" +
" </bpmndi:BPMNPlane>\n" +
" </bpmndi:BPMNDiagram>\n" +
"</bpmn2:definitions>\n";
try {
// 所需参数
String javaClass = "";
String finalName = "";
String finalValue = "";
// 解析XML字符串,得到document对象
Document document = DocumentHelper.parseText(bpmnXmlas);
// 获取根元素
Element rootOri = document.getRootElement();
// 添加属性
List<Namespace> namespaces = rootOri.declaredNamespaces();
List<String> rootNamespaces = new ArrayList<>();
for (Namespace namespace : namespaces) {
rootNamespaces.add(namespace.getPrefix());
}
if (!namespaces.contains("flowable")) {
rootOri.addAttribute("xmlns:flowable", "http://flowable.org/bpmn");
}
// 获取添加插件后的Document
// 需先添加xmlns:flowable插件,否则会报错No such namespace prefix: flowable is in scope on: org.dom4j.tree.DefaultEle......
Document documentUp = DocumentHelper.parseText(document.asXML());
Element rootElement = documentUp.getRootElement();
Iterator<Element> elementIterator = rootElement.elementIterator();
while (elementIterator.hasNext()) {
Element next = elementIterator.next();
if (next.getQualifiedName().equals("bpmn2:process")) {
System.out.println("bpmn2:process-------------" + next.getQualifiedName());
Iterator<Element> childElement = next.elementIterator();
while (childElement.hasNext()) {
Element itemEle = childElement.next();
if (itemEle.getQualifiedName().equals("bpmn2:serviceTask")) {
System.out.println("bpmn2:serviceTask------------" + itemEle.getQualifiedName());
List<Attribute> attributes = itemEle.attributes();
List<String> names = new ArrayList<>();
for (Attribute attribute : attributes) {
names.add(attribute.getQualifiedName());
}
// 存在则不添加
if (!names.contains("flowable:class")) {
itemEle.addAttribute("flowable:class", "com.lc.mono.shop.listener.ManagerTaskFunctionHandler");
}
// 获取子节点名称
Iterator iterator1 = itemEle.elementIterator();
while (iterator1.hasNext()) {
Element next1 = (Element) iterator1.next();
System.out.println("next1.getName------------" + next1.getName());
// 存在extensionElements
if (next1.getName().equals("extensionElements")) {
Iterator iterator2 = next1.elementIterator();
while (iterator2.hasNext()) {
Element next2 = (Element) iterator2.next();
System.out.println("next2.getName------------" + next2.getName());
if (next2.getName().equals("executionListener")) {
// 获取java类
Attribute aClass = next2.attribute("class");
javaClass = aClass.getValue();
System.out.println("获取java类==========" + aClass.getValue());
// 获取params
Iterator iterator3 = next2.elementIterator();
while (iterator3.hasNext()) {
Element next3 = (Element) iterator3.next();
Attribute name = next3.attribute("name");
finalName = name.getValue();
System.out.println("获取params==========" + name.getValue());
// 获取内容
Iterator iterator4 = next3.elementIterator();
while (iterator4.hasNext()) {
Element next4 = (Element) iterator4.next();
finalValue = next4.getStringValue();
System.out.println("获取内容==========" + next4.getStringValue());
}
}
// 解析完毕删除
next1.remove(next2);
Element extensionElements2 = null;
extensionElements2 = next1.addElement("flowable:field");
extensionElements2.addAttribute("name", finalName);
Element extensionElements3 = null;
extensionElements3 = extensionElements2.addElement("flowable:string");
extensionElements3.setText(finalValue);
}
}
} else {
System.out.println("请添加监听器规则(please add listener)");
}
}
}
}
}
}
// 1.声明文件名称
String fileName = "xml_test";
// 4、格式化模板
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("GBK");
// 5、生成xml文件
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, format);
writer.write(documentUp);
writer.close();
// 将文件输出到D盘
FileOutputStream fos = new FileOutputStream("D:/" + fileName + ".xml");
fos.write(out.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
}
7、添加flowable:executionListener标签
获取flowable:field标签内容,添加一层flowable:executionListener标签,将获取flowable:field标签内容封装到添加的标签中,并删除flowable:field标签
public static void main(String[] args) {
// xml字符串
String bpmnXmlas = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bpmn2:definitions xmlns:bpmn2=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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:flowable=\"http://flowable.org/bpmn\" id=\"diagram_Process_1663234442926\" targetNamespace=\"http://activiti.org/bpmn\"><bpmn2:process id=\"test9\" name=\"测试2022年9月19日16:23:01\" isExecutable=\"true\"><bpmn2:startEvent id=\"Event_1d982f4\"><bpmn2:outgoing>Flow_1a8zt74</bpmn2:outgoing></bpmn2:startEvent><bpmn2:exclusiveGateway id=\"Gateway_1kb5vve\"><bpmn2:incoming>Flow_1a8zt74</bpmn2:incoming><bpmn2:outgoing>Flow_1geuark</bpmn2:outgoing><bpmn2:outgoing>Flow_1asqvju</bpmn2:outgoing></bpmn2:exclusiveGateway><bpmn2:sequenceFlow id=\"Flow_1a8zt74\" sourceRef=\"Event_1d982f4\" targetRef=\"Gateway_1kb5vve\"/><bpmn2:sequenceFlow id=\"Flow_1geuark\" sourceRef=\"Gateway_1kb5vve\" targetRef=\"Activity_083ibjy\"><bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${condition == 'IP'}\n </bpmn2:conditionExpression></bpmn2:sequenceFlow><bpmn2:sequenceFlow id=\"Flow_1asqvju\" sourceRef=\"Gateway_1kb5vve\" targetRef=\"Activity_0579ovv\"><bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${condition == 'FILE'}\n </bpmn2:conditionExpression></bpmn2:sequenceFlow><bpmn2:serviceTask id=\"Activity_083ibjy\" name=\"IP情报\" flowable:class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\"><bpmn2:extensionElements><flowable:field name=\"params\"><flowable:string>{\"type\":\"console\",\"string\":\"IP情报\"}</flowable:string></flowable:field></bpmn2:extensionElements><bpmn2:incoming>Flow_1geuark</bpmn2:incoming><bpmn2:outgoing>Flow_0bopkdm</bpmn2:outgoing></bpmn2:serviceTask><bpmn2:serviceTask id=\"Activity_0579ovv\" name=\"文件情报\" flowable:class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\"><bpmn2:extensionElements><flowable:field name=\"params\"><flowable:string>{\"type\":\"console\",\"string\":\"文件情报\"}</flowable:string></flowable:field></bpmn2:extensionElements><bpmn2:incoming>Flow_1asqvju</bpmn2:incoming><bpmn2:outgoing>Flow_1ed3r0x</bpmn2:outgoing></bpmn2:serviceTask><bpmn2:exclusiveGateway id=\"Gateway_1dwwf2j\"><bpmn2:incoming>Flow_0bopkdm</bpmn2:incoming><bpmn2:outgoing>Flow_11k8mfp</bpmn2:outgoing><bpmn2:outgoing>Flow_0iibvpb</bpmn2:outgoing></bpmn2:exclusiveGateway><bpmn2:sequenceFlow id=\"Flow_0bopkdm\" sourceRef=\"Activity_083ibjy\" targetRef=\"Gateway_1dwwf2j\"/><bpmn2:sequenceFlow id=\"Flow_11k8mfp\" name=\"IP恶意\" sourceRef=\"Gateway_1dwwf2j\" targetRef=\"Activity_0n01hsi\"><bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'Y'}</bpmn2:conditionExpression></bpmn2:sequenceFlow><bpmn2:sequenceFlow id=\"Flow_0iibvpb\" name=\"IP不恶意\" sourceRef=\"Gateway_1dwwf2j\" targetRef=\"Activity_0ajbbgw\"><bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'N'}</bpmn2:conditionExpression></bpmn2:sequenceFlow><bpmn2:exclusiveGateway id=\"Gateway_06xn02q\"><bpmn2:incoming>Flow_1ed3r0x</bpmn2:incoming><bpmn2:outgoing>Flow_0j813j5</bpmn2:outgoing><bpmn2:outgoing>Flow_13w7ghd</bpmn2:outgoing></bpmn2:exclusiveGateway><bpmn2:sequenceFlow id=\"Flow_1ed3r0x\" sourceRef=\"Activity_0579ovv\" targetRef=\"Gateway_06xn02q\"/><bpmn2:sequenceFlow id=\"Flow_0j813j5\" name=\"文件可疑\" sourceRef=\"Gateway_06xn02q\" targetRef=\"Activity_0ysr2o8\"><bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'Y'}</bpmn2:conditionExpression></bpmn2:sequenceFlow><bpmn2:sequenceFlow id=\"Flow_1ugqxth\" sourceRef=\"Activity_0n01hsi\" targetRef=\"Activity_0i27q99\"/><bpmn2:sequenceFlow id=\"Flow_0uospyb\" sourceRef=\"Activity_0ajbbgw\" targetRef=\"Activity_0dlnxde\"/><bpmn2:endEvent id=\"Event_1ucrxbu\"><bpmn2:incoming>Flow_0vzshkg</bpmn2:incoming><bpmn2:incoming>Flow_0v2j0ig</bpmn2:incoming><bpmn2:incoming>Flow_0frjzww</bpmn2:incoming><bpmn2:incoming>Flow_13w7ghd</bpmn2:incoming></bpmn2:endEvent><bpmn2:sequenceFlow id=\"Flow_0vzshkg\" sourceRef=\"Activity_0i27q99\" targetRef=\"Event_1ucrxbu\"/><bpmn2:sequenceFlow id=\"Flow_0v2j0ig\" sourceRef=\"Activity_0dlnxde\" targetRef=\"Event_1ucrxbu\"/><bpmn2:serviceTask id=\"Activity_0ysr2o8\" name=\"隔离文件\" flowable:class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\"><bpmn2:extensionElements><flowable:field name=\"params\"><flowable:string>{\"type\":\"console\",\"string\":\"隔离文件\"}</flowable:string></flowable:field></bpmn2:extensionElements><bpmn2:incoming>Flow_0j813j5</bpmn2:incoming><bpmn2:outgoing>Flow_0frjzww</bpmn2:outgoing></bpmn2:serviceTask><bpmn2:sequenceFlow id=\"Flow_0frjzww\" sourceRef=\"Activity_0ysr2o8\" targetRef=\"Event_1ucrxbu\"/><bpmn2:sequenceFlow id=\"Flow_13w7ghd\" name=\"文件不可疑\" sourceRef=\"Gateway_06xn02q\" targetRef=\"Event_1ucrxbu\"><bpmn2:conditionExpression xsi:type=\"bpmn2:tFormalExpression\">${select == 'N'}</bpmn2:conditionExpression></bpmn2:sequenceFlow><bpmn2:serviceTask id=\"Activity_0ajbbgw\" name=\"策略\" flowable:class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\"><bpmn2:extensionElements><flowable:field name=\"params\"><flowable:string>{\"type\":\"console\",\"string\":\"策略\"}</flowable:string></flowable:field></bpmn2:extensionElements><bpmn2:incoming>Flow_0iibvpb</bpmn2:incoming><bpmn2:outgoing>Flow_0uospyb</bpmn2:outgoing></bpmn2:serviceTask><bpmn2:serviceTask id=\"Activity_0n01hsi\" name=\"IP阻断\" flowable:class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\"><bpmn2:extensionElements><flowable:field name=\"params\"><flowable:string>{\"type\":\"cmd\",\"cmd\":\"ipconfig\"}</flowable:string></flowable:field></bpmn2:extensionElements><bpmn2:incoming>Flow_11k8mfp</bpmn2:incoming><bpmn2:outgoing>Flow_1ugqxth</bpmn2:outgoing></bpmn2:serviceTask><bpmn2:serviceTask id=\"Activity_0i27q99\" name=\"创建工单\" flowable:class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\"><bpmn2:extensionElements><flowable:field name=\"params\"><flowable:string>{\"type\":\"console\",\"string\":\"创建工单\"}</flowable:string></flowable:field></bpmn2:extensionElements><bpmn2:incoming>Flow_1ugqxth</bpmn2:incoming><bpmn2:outgoing>Flow_0vzshkg</bpmn2:outgoing></bpmn2:serviceTask><bpmn2:serviceTask id=\"Activity_0dlnxde\" name=\"发送邮件\" flowable:class=\"com.lc.mono.shop.listener.ManagerTaskFunctionHandler\"><bpmn2:extensionElements><flowable:field name=\"params\"><flowable:string>{\"type\":\"console\",\"string\":\"发送邮件\"}</flowable:string></flowable:field></bpmn2:extensionElements><bpmn2:incoming>Flow_0uospyb</bpmn2:incoming><bpmn2:outgoing>Flow_0v2j0ig</bpmn2:outgoing></bpmn2:serviceTask></bpmn2:process><bpmndi:BPMNDiagram id=\"BPMNDiagram_1\"><bpmndi:BPMNPlane id=\"test9_di\" bpmnElement=\"test9\"><bpmndi:BPMNEdge id=\"Flow_13w7ghd_di\" bpmnElement=\"Flow_13w7ghd\"><di:waypoint x=\"550\" y=\"375\"/><di:waypoint x=\"550\" y=\"510\"/><di:waypoint x=\"1060\" y=\"510\"/><di:waypoint x=\"1060\" y=\"188\"/><bpmndi:BPMNLabel><dc:Bounds x=\"778\" y=\"492\" width=\"55\" height=\"14\"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_0frjzww_di\" bpmnElement=\"Flow_0frjzww\"><di:waypoint x=\"810\" y=\"350\"/><di:waypoint x=\"1060\" y=\"350\"/><di:waypoint x=\"1060\" y=\"188\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_0v2j0ig_di\" bpmnElement=\"Flow_0v2j0ig\"><di:waypoint x=\"910\" y=\"220\"/><di:waypoint x=\"976\" y=\"220\"/><di:waypoint x=\"976\" y=\"170\"/><di:waypoint x=\"1042\" y=\"170\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_0vzshkg_di\" bpmnElement=\"Flow_0vzshkg\"><di:waypoint x=\"910\" y=\"-20\"/><di:waypoint x=\"976\" y=\"-20\"/><di:waypoint x=\"976\" y=\"170\"/><di:waypoint x=\"1042\" y=\"170\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_0uospyb_di\" bpmnElement=\"Flow_0uospyb\"><di:waypoint x=\"740\" y=\"220\"/><di:waypoint x=\"810\" y=\"220\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_1ugqxth_di\" bpmnElement=\"Flow_1ugqxth\"><di:waypoint x=\"730\" y=\"-20\"/><di:waypoint x=\"810\" y=\"-20\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_0j813j5_di\" bpmnElement=\"Flow_0j813j5\"><di:waypoint x=\"575\" y=\"350\"/><di:waypoint x=\"710\" y=\"350\"/><bpmndi:BPMNLabel><dc:Bounds x=\"622\" y=\"332\" width=\"44\" height=\"14\"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_1ed3r0x_di\" bpmnElement=\"Flow_1ed3r0x\"><di:waypoint x=\"460\" y=\"350\"/><di:waypoint x=\"525\" y=\"350\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_0iibvpb_di\" bpmnElement=\"Flow_0iibvpb\"><di:waypoint x=\"550\" y=\"135\"/><di:waypoint x=\"550\" y=\"220\"/><di:waypoint x=\"640\" y=\"220\"/><bpmndi:BPMNLabel><dc:Bounds x=\"557\" y=\"175\" width=\"45\" height=\"14\"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_11k8mfp_di\" bpmnElement=\"Flow_11k8mfp\"><di:waypoint x=\"550\" y=\"85\"/><di:waypoint x=\"550\" y=\"-20\"/><di:waypoint x=\"630\" y=\"-20\"/><bpmndi:BPMNLabel><dc:Bounds x=\"563\" y=\"30\" width=\"34\" height=\"14\"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_0bopkdm_di\" bpmnElement=\"Flow_0bopkdm\"><di:waypoint x=\"460\" y=\"110\"/><di:waypoint x=\"525\" y=\"110\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_1asqvju_di\" bpmnElement=\"Flow_1asqvju\"><di:waypoint x=\"270\" y=\"265\"/><di:waypoint x=\"270\" y=\"350\"/><di:waypoint x=\"360\" y=\"350\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_1geuark_di\" bpmnElement=\"Flow_1geuark\"><di:waypoint x=\"270\" y=\"215\"/><di:waypoint x=\"270\" y=\"110\"/><di:waypoint x=\"360\" y=\"110\"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id=\"Flow_1a8zt74_di\" bpmnElement=\"Flow_1a8zt74\"><di:waypoint x=\"188\" y=\"240\"/><di:waypoint x=\"245\" y=\"240\"/></bpmndi:BPMNEdge><bpmndi:BPMNShape id=\"Event_1d982f4_di\" bpmnElement=\"Event_1d982f4\"><dc:Bounds x=\"152\" y=\"222\" width=\"36\" height=\"36\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Gateway_1kb5vve_di\" bpmnElement=\"Gateway_1kb5vve\" isMarkerVisible=\"true\"><dc:Bounds x=\"245\" y=\"215\" width=\"50\" height=\"50\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Activity_0n3lstu_di\" bpmnElement=\"Activity_083ibjy\"><dc:Bounds x=\"360\" y=\"70\" width=\"100\" height=\"80\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Activity_1u8478q_di\" bpmnElement=\"Activity_0579ovv\"><dc:Bounds x=\"360\" y=\"310\" width=\"100\" height=\"80\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Gateway_1dwwf2j_di\" bpmnElement=\"Gateway_1dwwf2j\" isMarkerVisible=\"true\"><dc:Bounds x=\"525\" y=\"85\" width=\"50\" height=\"50\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Gateway_06xn02q_di\" bpmnElement=\"Gateway_06xn02q\" isMarkerVisible=\"true\"><dc:Bounds x=\"525\" y=\"325\" width=\"50\" height=\"50\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Event_1ucrxbu_di\" bpmnElement=\"Event_1ucrxbu\"><dc:Bounds x=\"1042\" y=\"152\" width=\"36\" height=\"36\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Activity_0ipps3t_di\" bpmnElement=\"Activity_0ysr2o8\"><dc:Bounds x=\"710\" y=\"310\" width=\"100\" height=\"80\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Activity_0073q7h_di\" bpmnElement=\"Activity_0ajbbgw\"><dc:Bounds x=\"640\" y=\"180\" width=\"100\" height=\"80\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Activity_0nx7c34_di\" bpmnElement=\"Activity_0n01hsi\"><dc:Bounds x=\"630\" y=\"-60\" width=\"100\" height=\"80\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Activity_0alrvbz_di\" bpmnElement=\"Activity_0i27q99\"><dc:Bounds x=\"810\" y=\"-60\" width=\"100\" height=\"80\"/></bpmndi:BPMNShape><bpmndi:BPMNShape id=\"Activity_1mgp02f_di\" bpmnElement=\"Activity_0dlnxde\"><dc:Bounds x=\"810\" y=\"180\" width=\"100\" height=\"80\"/></bpmndi:BPMNShape></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></bpmn2:definitions>";
try {
// 所需参数
String javaClass = "";
String finalName = "";
String finalValue = "";
// 解析XML字符串,得到document对象
Document document = DocumentHelper.parseText(bpmnXmlas);
// 获取根元素
Element rootOri = document.getRootElement();
// 添加属性
List<Namespace> namespaces = rootOri.declaredNamespaces();
List<String> rootNamespaces = new ArrayList<>();
for (Namespace namespace : namespaces) {
rootNamespaces.add(namespace.getPrefix());
}
if (!namespaces.contains("flowable")) {
rootOri.addAttribute("xmlns:flowable", "http://flowable.org/bpmn");
}
// 获取添加插件后的Document
// 需先添加xmlns:flowable插件,否则会报错No such namespace prefix: flowable is in scope on: org.dom4j.tree.DefaultEle......
Document documentUp = DocumentHelper.parseText(document.asXML());
Element rootElement = documentUp.getRootElement();
Iterator<Element> elementIterator = rootElement.elementIterator();
while (elementIterator.hasNext()) {
Element next = elementIterator.next();
if (next.getQualifiedName().equals("bpmn2:process")) {
System.out.println("bpmn2:process-------------" + next.getQualifiedName());
Iterator<Element> childElement = next.elementIterator();
while (childElement.hasNext()) {
Element itemEle = childElement.next();
if (itemEle.getQualifiedName().equals("bpmn2:serviceTask")) {
System.out.println("bpmn2:serviceTask------------" + itemEle.getQualifiedName());
javaClass = itemEle.attribute("class").getValue();
System.out.println("javaClass = " + javaClass);
// 获取子节点名称
Iterator iterator1 = itemEle.elementIterator();
while (iterator1.hasNext()) {
Element next1 = (Element) iterator1.next();
System.out.println("next1.getName------------" + next1.getName());
// 存在extensionElements
if (next1.getName().equals("extensionElements")) {
Iterator iterator2 = next1.elementIterator();
while (iterator2.hasNext()) {
Element next2 = (Element) iterator2.next();
System.out.println("next2.getName------------" + next2.getName());
String name = next2.attribute("name").getValue();
System.out.println("name = " + name);
// 获取内容
Iterator iterator3 = next2.elementIterator();
while (iterator3.hasNext()) {
Element next3 = (Element) iterator3.next();
finalValue = next3.getStringValue();
System.out.println("finalValue = " + finalValue);
}
Element element = next1.addElement("flowable:executionListener");
element.addAttribute("class", javaClass);
element.addAttribute("event", "start");
Element extensionElements2 = null;
extensionElements2 = element.addElement("flowable:field");
extensionElements2.addAttribute("name", name);
Element extensionElements3 = null;
extensionElements3 = extensionElements2.addElement("flowable:string");
extensionElements3.setText(finalValue);
}
} else {
System.out.println("请添加监听器规则(please add listener)");
}
}
}
}
}
}
// 1.声明文件名称
String fileName = "xml_test";
// 4、格式化模板
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("GBK");
// 5、生成xml文件
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, format);
writer.write(documentUp);
writer.close();
// 将文件输出到D盘
FileOutputStream fos = new FileOutputStream("D:/" + fileName + ".xml");
fos.write(out.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
}
旧:
<bpmn2:serviceTask id="Activity_083ibjy" name="IP情报" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:extensionElements>
<flowable:field name="params">
<flowable:expression>{"type":"console","string":"IP情报"}</flowable:expression>
</flowable:field>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_1geuark</bpmn2:incoming>
<bpmn2:outgoing>Flow_0bopkdm</bpmn2:outgoing>
</bpmn2:serviceTask>
新:
<bpmn2:serviceTask id="Activity_0579ovv" name="文件情报" flowable:class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler">
<bpmn2:extensionElements>
<flowable:executionListener class="com.lc.mono.shop.listener.ManagerTaskFunctionHandler" event="start">
<flowable:field name="params">
<flowable:string>{"type":"console","string":"文件情报"}</flowable:string>
</flowable:field>
</flowable:executionListener>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_1asqvju</bpmn2:incoming>
<bpmn2:outgoing>Flow_1ed3r0x</bpmn2:outgoing>
</bpmn2:serviceTask>