久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 xml.etree.ElementTree 獲取子節點的所有實例

Getting all instances of child node using xml.etree.ElementTree(使用 xml.etree.ElementTree 獲取子節點的所有實例)
本文介紹了使用 xml.etree.ElementTree 獲取子節點的所有實例的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有以下 XML 文件作為輸入:

I have the following XML file as input:

<Test>
  <callEvents>
    <moc>
      <causeForTermination>0</causeForTermination>
      <serviceCode>
        <teleServiceCode>11</teleServiceCode>
      </serviceCode>
      <dialledDigits>5555555</dialledDigits>
      <connectedNumber>77777</connectedNumber>
    </moc>

    <moc>
      <causeForTermination>0</causeForTermination>
      <serviceCode>
        <teleServiceCode>11</teleServiceCode>
      </serviceCode>
      <dialledDigits>2222222</dialledDigits>
    </moc>
  </callEvents>
  <callEventsCount>100</callEventsCount>
</Test> 

我想輸出 dialledDigits 的所有值.但是,我的代碼只顯示 dialledDigits 的第一個實例.

I want to output all the values for dialledDigits. However, my code only displays the first instance of dialledDigits.

dialledDigits {} 5555555

我想要的輸出應該包含這兩個實例.

My desired output should contain both instances.

dialledDigits {} 5555555
dialledDigits {} 2222222

這是我的代碼

import xml.etree.ElementTree as ET
tree = ET.parse('as.xml')
root = tree.getroot()
callevent=root.find('callEvents')

Moc1=callevent.find('moc')

for node in Moc1.getiterator():
    if node.tag=='dialledDigits':
        print node.tag, node.attrib, node.text

推薦答案

使用findall:

moc1 = callevent.findall('moc')

for moc in moc1:
    for node in moc.getiterator():
        if node.tag=='dialledDigits':
            print node.tag, node.attrib, node.text

輸出:

dialledDigits {} 5555555
dialledDigits {} 2222222

這篇關于使用 xml.etree.ElementTree 獲取子節點的所有實例的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: www性色 | 国产传媒毛片精品视频第一次 | 亚洲一区 中文字幕 | 亚洲国产免费 | 日本在线观看视频 | 亚洲精品日韩视频 | 黄色片免费看视频 | 蜜桃日韩| 男人的天堂中文字幕 | 91国内精品久久 | 超碰最新在线 | 激情黄色在线观看 | 国产做a爱片久久毛片 | 中文字幕二区 | 麻豆成人在线视频 | 亚洲天堂久久新 | 欧美亚洲另类在线 | 自拍偷拍中文字幕 | 免费精品 | 精品国产视频 | 日韩三级 | 精品不卡 | 日韩视频在线免费观看 | 国产欧美精品一区二区三区 | 中文字幕av亚洲精品一部二部 | 国产精品视频在线观看 | 亚洲视频免费观看 | 亚洲精品视频在线看 | 亚洲激情视频在线 | 国产精品a久久久久 | 国产精品成人av | 日韩在线免费视频 | 北条麻妃国产九九九精品小说 | 欧美日韩视频在线第一区 | 亚洲成人精品 | 91视频一88av | 日韩av一区在线观看 | 91色视频在线观看 | 日韩最新网站 | 在线成人www免费观看视频 | 韩日一区二区 |