Python-lxml库保存XML

xml_Stations = ET.Element('StationInfo')
for x in G.nodes:
    xml_Stations.append(rootLoc.find('./station[@name="%s"]'%x))
tree = ET.ElementTree(xml_Stations)
tree.write('output.xml', pretty_print=True, xml_declaration=True,   encoding="utf-8")

你可能感兴趣的:(Python-lxml库保存XML)