从当前元素找不到命名空间属性

时间:2019-02-04 03:51:07

标签: python xml xml-parsing elementtree

嗨,我有以下XML,并且我正在使用python ElementTree库进行解析。

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0qjsjhs" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.2.4">
 <bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
  <bpmn:outgoing>SequenceFlow_0bwuv8k</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_0bwuv8k" sourceRef="StartEvent_1" targetRef="Task_07owcwp" />
<bpmn:endEvent id="EndEvent_13n8600">
  <bpmn:incoming>SequenceFlow_111n6oc</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_111n6oc" sourceRef="Task_07owcwp" targetRef="EndEvent_13n8600">
  <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">myexpression.</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:scriptTask id="Task_07owcwp" scriptFormat="testformat" camunda:resultVariable="output">
  <bpmn:incoming>SequenceFlow_0bwuv8k</bpmn:incoming>
  <bpmn:outgoing>SequenceFlow_111n6oc</bpmn:outgoing>
  <bpmn:script>myscript</bpmn:script>
</bpmn:scriptTask>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2"  bpmnElement="StartEvent_1">
    <dc:Bounds x="173" y="102" width="36" height="36" />
  </bpmndi:BPMNShape>
  <bpmndi:BPMNEdge id="SequenceFlow_0bwuv8k_di" bpmnElement="SequenceFlow_0bwuv8k">
    <di:waypoint x="209" y="120" />
    <di:waypoint x="266" y="120" />
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNShape id="EndEvent_13n8600_di" bpmnElement="EndEvent_13n8600">
    <dc:Bounds x="423" y="102" width="36" height="36" />
  </bpmndi:BPMNShape>
  <bpmndi:BPMNEdge id="SequenceFlow_111n6oc_di" bpmnElement="SequenceFlow_111n6oc">
    <di:waypoint x="366" y="120" />
    <di:waypoint x="423" y="120" />
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNShape id="ScriptTask_1p2sdkp_di" bpmnElement="Task_07owcwp">
    <dc:Bounds x="266" y="80" width="100" height="80" />
  </bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
  </bpmn:definitions>`

我目前在'bpmn:scripttask'元素上,在解决如何提取'camunda:resultVariable'的值时遇到问题

<bpmn:scriptTask id="Task_07owcwp" scriptFormat="testformat" camunda:resultVariable="output">
  <bpmn:incoming>SequenceFlow_0bwuv8k</bpmn:incoming>
  <bpmn:outgoing>SequenceFlow_111n6oc</bpmn:outgoing>
  <bpmn:script>myscript</bpmn:script>
</bpmn:scriptTask>

我尝试过

node.find('camunda:resultVariable' {'camunda':'http://camunda.org/schema/1.0/bpmn'}

其中节点是ElementTree对象scriptTask。确实找到或找到了所有您要查看的当前元素属性,因为似乎没有找到它。我将如何寻找这个价值?

谢谢。

1 个答案:

答案 0 :(得分:0)

好的,我解决了。我可以使用.get,但是我需要像这样扩展名称空间

node.get('{http://camunda.org/schema/1.0/bpmn}resultVariable')