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

  • 相关阅读:
    人件阅读笔记之三
    明日计划:团队开发Fooks第十天
    明日计划:团队开发Fooks第九天
    明日计划:团队开发Fooks第八天
    明日计划:团队开发Fooks第七天
    明日计划:团队开发Fooks第六天
    优先队列
    KMP
    django-中间件
    Ajax--参数,csrf跨站请求伪造,serialize(),上传文件formdata
  • 原文地址:https://www.cnblogs.com/jiawen010/p/9907772.html
Copyright © 2011-2022 走看看