1

我正在尝试使用 xquery 获取一些信息。但是 xml-element 有一个带有名称的冒号

我确实知道问题与命名空间有关,但是当我使用一个简单的 xquery 解释器时,我不知道该怎么做。

这是我的方法,但是

let $e := doc('C:\Users\Katharina\workspace\BPMN\process_1.bpmn')
(: for $k in $e//*[name()='bpmn2:task']:)
for $k in $e
return $k

但是我对更改后的代码一无所知..

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="Definitions_1" targetNamespace="http://sample.bpmn2.org/bpmn2/sample/process">
  <bpmn2:itemDefinition id="ItemDefinition_2" itemKind="Physical" structureRef="I"/>
  <bpmn2:process id="process_1" name="Default Process">
    <bpmn2:task id="Task_2" name="Task 2">
      <bpmn2:incoming>SequenceFlow_6</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_9</bpmn2:outgoing>
    </bpmn2:task>
    <bpmn2:parallelGateway id="ParallelGateway_1" name="Parallel Gateway 1" gatewayDirection="Diverging">
      <bpmn2:incoming>SequenceFlow_9</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_10</bpmn2:outgoing>
      <bpmn2:outgoing>SequenceFlow_11</bpmn2:outgoing>
    </bpmn2:parallelGateway>
    <bpmn2:sequenceFlow id="SequenceFlow_9" name="Sequence Flow 9" sourceRef="Task_2" targetRef="ParallelGateway_1"/>
    <bpmn2:sequenceFlow id="SequenceFlow_10" sourceRef="ParallelGateway_1" targetRef="Task_3"/>
    <bpmn2:task id="Task_3" name="Task 3">
      <bpmn2:incoming>SequenceFlow_10</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_12</bpmn2:outgoing>
    </bpmn2:task>
    <bpmn2:sequenceFlow id="SequenceFlow_11" sourceRef="ParallelGateway_1" targetRef="Task_4"/>
    <bpmn2:task id="Task_4" name="Task 4">
      <bpmn2:incoming>SequenceFlow_11</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_13</bpmn2:outgoing>
    </bpmn2:task>
    <bpmn2:sequenceFlow id="SequenceFlow_12" sourceRef="Task_3" targetRef="ParallelGateway_2"/>
    <bpmn2:parallelGateway id="ParallelGateway_2" name="Parallel Gateway 2" gatewayDirection="Converging">
      <bpmn2:incoming>SequenceFlow_12</bpmn2:incoming>
      <bpmn2:incoming>SequenceFlow_13</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_14</bpmn2:outgoing>
    </bpmn2:parallelGateway>
    <bpmn2:sequenceFlow id="SequenceFlow_13" name="Sequence Flow 13" sourceRef="Task_4" targetRef="ParallelGateway_2"/>
    <bpmn2:sequenceFlow id="SequenceFlow_14" sourceRef="ParallelGateway_2" targetRef="Task_5"/>
    <bpmn2:endEvent id="EndEvent_2" name="End Event 2">
      <bpmn2:incoming>SequenceFlow_15</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:task id="Task_5" name="Task 5">
      <bpmn2:incoming>SequenceFlow_14</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_15</bpmn2:outgoing>
    </bpmn2:task>
    <bpmn2:sequenceFlow id="SequenceFlow_15" name="Sequence Flow 15" sourceRef="Task_5" targetRef="EndEvent_2"/>
    <bpmn2:startEvent id="StartEvent_2" name="Start Event 2">
      <bpmn2:outgoing>SequenceFlow_6</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_6" sourceRef="StartEvent_2" targetRef="Task_2"/>
  </bpmn2:process>
</bpmn2:definitions>
4

1 回答 1

1

只需在 XQuery 代码中声明名称空间 URI。

declare namespace bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL";

let $e := doc('C:\Users\Katharina\workspace\BPMN\process_1.bpmn')

for $k in $e//bpmn2:task
    return $k
于 2013-10-08T15:27:24.253 回答