【问题标题】:Cannot find a namespaced attribute from current element无法从当前元素中找到命名空间属性
【发布时间】:2019-02-04 03:51:07
【问题描述】:

您好,我有以下 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'}

其中 node 是一个 ElementTree 对象 scriptTask。确实 find 或 findall 来查看当前元素属性,因为它似乎没有找到它。我将如何找到这个值?

谢谢。

【问题讨论】:

    标签: python xml xml-parsing elementtree


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 1970-01-01
      • 1970-01-01
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多