分析python“object”时出现错误:“attributexmeror”元素没有

2024-10-01 13:27:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python世界非常陌生,我有一个新的要求,我需要打印节点值和节点名Python。但是我遇到了一些错误。 谁能帮我。。。!!!!在

这是我的xml示例:

  <task chapnbr="05" sectnbr="41" subjnbr="05" func="210" seq="8" pgblknbr="2" chg="N" key="4B5014E906" revdate="20051230">
      <effect effrg="801899" efftext="ZAP ALL" />
      <title>WING</title>
      <refblock>(<grphcref refid=NAX00000>Figure 208</grphcref>)</refblock>
      <tfmatr>
        <pretopic>
          <title>General</title>
          <list1>
            <l1item>
              <para>This procedure is a scheduled maintenance task.</para>
            </l1item>
          </list1>
        </pretopic>
      </tfmatr>
      <topic>
        <title>Zonal Inspection</title>
        <subtask chapnbr="05" sectnbr="41" subjnbr="05" func="210" seq="008" pgblknbr="2" chg="N" key="B7A276D9D" revdate="20051230">
          <effect effrg="8018" efftext="ZAP ALL" />
          <list1>
            <l1item>
              <para>Do the zonal inspection.</para>
            </l1item>
          </list1>
        </subtask>
      </topic>
      <graphic chapnbr="05" sectnbr="41" subjnbr="05" func="990" seq="808" pgblknbr="2" chg="N" key=NAX00000 revdate="20051230">
        <effect effrg="801899" efftext="ZAP ALL" />
        <title>Figure 208. Leading Edge to Front Spar (Outboard of Nacelle Strut) Left Wing - General Visual (External)</title>
        <sheet gnbr="811DE0C" sheetnbr="1" chg="N" key="5C152" revdate="20051230">
          <effect effrg="801899" efftext="ZAP ALL" />
        </sheet>
      </graphic>
    </task>

我的python代码示例:

^{pr2}$

我正在低于错误。在

enter image description here


Tags: keytasktitleallzapparaeffectlist1
1条回答
网友
1楼 · 发布于 2024-10-01 13:27:21

因为xml.etree.ElementTree.Element对象没有属性childNodes。在

要迭代childern元素,只需执行for child in elem。在

def print_node(root):
    for node in root:
       if node.nodeType == node.ELEMENT_NODE:
           print node.tagName,"has value:",  node.nodeValue, "and is child of:", node.parentNode.tagName
           print_node(node)

相关问题 更多 >