zoukankan      html  css  js  c++  java
  • xml模块

     1 # import xml.etree.ElementTree as ET
     2 #
     3 #
     4 #
     5 # tree = ET.parse("xml_lesson")
     6 # root = tree.getroot()
     7 # print(root.tag)
     8 
     9 
    10 # for i in root:
    11 #
    12 #     #print(i.tag)
    13 #     #print(i.attrib)
    14 #     for j in i:
    15 #         #print(j.tag)
    16 #         #print(j.attrib)
    17 #         print(j.text)
    18 
    19 
    20 
    21 
    22 # # 遍历xml文档
    23 # for child in root:
    24 #     print(child.tag, child.attrib)
    25 #     for i in child:
    26 #         print(i.tag, i.text)
    27 
    28 # 只遍历year 节点
    29 # for node in root.iter('year'):
    30 #     print(node.tag, node.text)
    31 # # ---------------------------------------
    32 
    33 # import xml.etree.ElementTree as ET
    34 #
    35 # tree = ET.parse("xml_lesson")
    36 # root = tree.getroot()
    37 
    38 # 修改
    39 # for node in root.iter('year'):
    40 #     new_year = int(node.text) + 1
    41 #     node.text = str(new_year)
    42 #     node.set("updated", "yes")
    43 #
    44 # tree.write("xml_lesson")
    45 #
    46 # 删除node
    47 # for country in root.findall('country'):
    48 #     rank = int(country.find('rank').text)
    49 #     if rank > 50:
    50 #         root.remove(country)
    51 #
    52 # tree.write('output.xml')
    53 
    54 
    55 # import xml.etree.ElementTree as ET
    56 #
    57 # new_xml = ET.Element("namelist")
    58 #
    59 # name = ET.SubElement(new_xml, "name", attrib={"enrolled": "yes"})
    60 # age = ET.SubElement(name, "age", attrib={"checked": "no"})
    61 # sex = ET.SubElement(name, "sex")
    62 # sex.text = '33'
    63 # name2 = ET.SubElement(new_xml, "name", attrib={"enrolled": "no"})
    64 # age = ET.SubElement(name2, "age")
    65 # age.text = '19'
    66 
    67 
    68 
    69 et = ET.ElementTree(new_xml)  # 生成文档对象
    70 et.write("test.xml", encoding="utf-8", xml_declaration=True)
    71 
    72 #ET.dump(new_xml)  # 打印生成的格式

     原文链接:https://www.cnblogs.com/yuanchenqi/articles/5732581.html

  • 相关阅读:
    为什么 PCB 生产时推荐出 Gerber 给工厂?
    Fedora Redhat Centos 有什么区别和关系?
    【KiCad】 如何给元件给元件的管脚加上划线?
    MCU ADC 进入 PD 模式后出现错误的值?
    FastAdmin 生产环境升级注意
    EMC EMI 自行评估记录
    如何让你的 KiCad 在缩放时不眩晕?
    KiCad 5.1.0 正式版终于发布
    一次单片机 SFR 页引发的“事故”
    java基础之集合
  • 原文地址:https://www.cnblogs.com/jiawen010/p/9907772.html
Copyright © 2011-2022 走看看