编程随想
Python解析xml
import xml.dom.minidom
xmlstr = '''<NetworkInterfaceList><NetworkInterface>
<ipAddress>15.18.91.195</ipAddress>
<subnetMask>255.255.255.240</subnetMask>
<MACAddress>a4:14:37:7b:a8:d2</MACAddress>
</NetworkInterface></NetworkInterfaceList>'''
DOMTree = xml.dom.minidom.parseString(xmlstr) //直接读取字符串
#DOMTree = xml.dom.minidom.parse("xmlstr.xml") //读取xml文件
config = DOMTree.documentElement.getElementsByTagName("NetworkInterface")
ipAddress = config[0].getElementsByTagName('ipAddress')[0]
subnetMask = config[0].getElementsByTagName('subnetMask')[0]
MACAddress = config[0].getElementsByTagName('MACAddress')[0]
row = [ipAddress.childNodes[0].data,subnetMask.childNodes[0].data,MACAddress.childNodes[0].data]
print(row) //['15.18.91.195', '255.255.255.240', 'a4:14:37:7b:a8:d2']