python xml解析

具体文档参见:http://docs.python.org/library/xml.etree.elementtree.html

例子:

#-*-coding:utf-8-*-
from xml.etree import ElementTree as ET

file = ET.parse('ftp.xml')
ftps = file.findall('/ftp')
for ftp in ftps:
    print ftp.attrib
    print ftp.get('name')
    print ftp.get('ip')
    print ftp.get('username')
ftp.xml 文件:
<?
xml version = "1.0" encoding= "UTF-8"?> <TotalFTP> <ftp name='ftpUbuntu' ip='192.168.88.245' port ='21' username = 'hzhida' password = 'dingjia'/> <ftp name='windowftp' ip='192.168.88.162' port = '21' username = 'hzhida' pasword = 'dingjia'/> </TotalFTP>
原文地址:https://www.cnblogs.com/hzhida/p/2643357.html