我遇到了Xquery的问题
我有一个像这样的XML文档
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions .....">
<bpmn2:process id="process_3" drools:version="1" drools:packageName="defaultPackage"drools:adHoc="false" name="Default Process" isExecutable="true">
<bpmn2:startEvent id="StartEvent_1" name="">
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:endEvent id="EndEvent_1" name="">
<bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="SequenceFlow_3" name="Sequence Flow 3" sourceRef="StartEvent_1" targetRef="ManualTask_1"/>
<bpmn2:manualTask id="ManualTask_1" timeToComplete="300" name="Manual Task 1">
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
</bpmn2:manualTask>
<bpmn2:manualTask id="ManualTask_2" timeToComplete="200" name="Manual Task 2">
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing>
</bpmn2:manualTask>
<bpmn2:sequenceFlow id="SequenceFlow_1" name="Sequence Flow 1" sourceRef="ManualTask_1" targetRef="ManualTask_2"/>
<bpmn2:sequenceFlow id="SequenceFlow_4" name="Sequence Flow 4" sourceRef="ManualTask_2" targetRef="EndEvent_1"/>
</bpmn2:process>
</bpmn2:definitions>
我想得到下一个元素。(来自最后一个元素的传出序列流应该是de incoming element(sequenceflow)(所以一个manualTask或一个EndEvent(或者简化为不同的东西)(所有这些元素都有传入的标签) )
declare namespace bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL";
let $elements := doc('file:///C:\..\process3.txt')/bpmn2:definitions/bpmn2:process,
$e := $elements/bpmn2:startEvent
return $elements[//bpmn2:incoming/node() = $e//bpmn2:outgoing]
这在BaseX中只返回完整的$元素而不是..而且此刻我觉得很难......
答案 0 :(得分:0)
现在你的$ elements var只包含一个元素:process元素。你想要的是它包含该元素的所有子元素,因此应该是bpmn2:process / *
那么你的$ e变量也需要改变一点(见下文)和你最后一行的//应该是.//因为你想在$ elements变量的上下文中对它进行评估
最终查询应该是这样的:
declare namespace bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL";
let $elements := doc('file:///C:\..\process3.txt')/bpmn2:definitions/bpmn2:process/*,
$e := $elements[self::bpmn2:startEvent]
return $elements[.//bpmn2:incoming/node() = $e//bpmn2:outgoing]