Xpath 处理带有命名空间的xml

本文介绍了一个基于JBPM的资金支付流程实例,详细展示了从填单到审核的全过程,并针对不同金额设置了不同的审批流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<?xml version="1.0" encoding="utf-8"?>
<process xmlns="http://jbpm.org/4.4/jpdl" key="payment" name="资金支付">
<start name="start1" g="265,50,48,48">
<transition name="to task1" to="填单" g="-53,-17"/>
</start>
<!-- candidate-users="1000201100000000036,1000201100000000034" -->
<task name="填单" g="243,132,92,52" assignee="1000201100000000036">
<transition name="提交" to="exclusive1" g="-83,-17"/>
</task>
<decision name="exclusive1" g="266,208,48,48" expr="#{finance > 500 ? '大量资金' : '一般资金'}" >
<transition name="一般资金" to="一般资金" g="-53,-17"/>
<transition name="大量资金" to="大量资金" g="-53,-17"/>

</decision>
<task name="一般资金" g="153,290,92,52" assignee="1000201100000000034">
<transition name="通过" to="end1" g="-47,-17"/>
</task>
<task name="大量资金" g="332,288,92,52" assignee="1000201100000000033">
<transition name="通过" to="end1" g="-47,-17"/>
</task>
<end name="end1" g="268,379,48,48"/>
</process>



SAXReader saxReader = new SAXReader();
Document document;
try {
document = saxReader.read(new File(path + processKey));
Map<String, String> nameSpaceMap = new HashMap<String, String>();
nameSpaceMap.put("jbpm", "http://jbpm.org/4.4/jpdl");
//设置命名空间
saxReader.getDocumentFactory().setXPathNamespaceURIs(nameSpaceMap);
//使用xpath找节点的时候前面加 jbpm: 就可以找到。
Element eleTask = (Element) document.selectSingleNode("/process/jbpm:decision[@name='" + nodeName + "']");
OutputFormat format = new OutputFormat("", false, "utf-8"); // 设置输出格式为空两格,换行,编码为utf-8
XMLWriter writer = new XMLWriter(new FileOutputStream(path +processKey), format); // 创建输出对象
writer.write(document);
writer.close();
} catch (DocumentException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值