带冒号的Xpath / Xquery

时间:2013-10-08 15:12:29

标签: xml xpath xquery

我正在尝试使用xquery获取一些信息。 但是xml-element有一个名为

的冒号

我知道问题必须与命名空间有关,但是当我使用简单的xquery intepreter时,我不知道该怎么做。

这是我的方法,但是

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>

1 个答案:

答案 0 :(得分: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