python:访问xml的两种方式
上一篇 /
下一篇 2011-08-29 12:34:34
/ 个人分类:python
def readXML(filename):
try:
if re.search('.xml$', filename):
XML=ET.parse(os.getcwd()+filename) #xml为xml文件
else:
XML=ET.fromstring(filename) #xml为字符串
return XML
except Exception, e:
print "readXML", e
return -1
#xml为xml文件
config = readXML("./config.xml")
webInfo=config.find('webInfo')
Domain=webInfo.find('Domain').text
profile=webInfo.find('profile').text
#xml为字符串
html="<authenticationinfo><info><profile>wuling</profile><displayname>wuling</displayname><peerid>wuling@tonidoid.com</peerid><authenticated>1</authenticated><isremote>1</isremote><reasoncode>0</reasoncode></info></authenticationinfo>"
root=readXML(html)
result=root.find("command/result")
secretqn=root.find("command/message")
收藏
举报
TAG: