无法找到当前元素的命名空间属性

问题描述 投票:0回答:1

嗨,我有以下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。是否找到或所有的findAll你看看目前的元素属性,因为它似乎并没有被找到它。我将如何去寻找这个价值?

谢谢。

python xml xml-parsing elementtree
1个回答
0
投票

好,我的工作了。我可以用不用彷徨,但我需要扩展出像这样的命名空间

node.get('{http://camunda.org/schema/1.0/bpmn}resultVariable')
© www.soinside.com 2019 - 2024. All rights reserved.