a="""<?xml version="1.0" encoding="utf-8"?>
<catalog>
<maxid>4</maxid>
<login username="pytest" passwd='123456'>
<caption>Python</caption>
<item id="4">
<caption>测试</caption>
</item>
</login>
<item id="2">
<caption>Zope</caption>
</item>
</catalog>
"""
import xml.dom.minidom
#打开文件用xml.dom.minidom.parse('a.xml')
dom = xml.dom.minidom.parseString(a)
root = dom.documentElement
bb = root.getElementsByTagName('caption')
b = bb[1]
uu = b.firstChild.data
print(uu)
a = root.getElementsByTagName('login')
a = a[0]
a = a.getAttribute('passwd')
print(a)
发下一个更好的:
defback(request): ifrequest.method=='POST': print(request) print(request.body) #print(request.raw_post_data) xml=request.body a=ObjectDict(dict((child.tag,child.text)forchildinET.fromstring(xml))) print(a) print(a.ToUserName) #print(a.Event) returnHttpResponse(json.dumps(a)) returnHttpResponse('hi')原文链接:https://www.f2er.com/xml/296104.html