xml_data() xml转字典
xml_data() 接收一个参数,第一个参数为要转换的xml数据
以下是 xml_data() 的语法:
1 | xml_data(data) |
● data [类型]:需要转字典的xml数据。
返回一个dict类型的数据
以下展示了使用 xml_data() 的实例:
1 2 3 4 5 6 7 8 9 10 11 | from kyger.common import xml_data data = """ <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[this is a test]]></Content> <MsgId>1234567890123456</MsgId> </xml>""" print (xml_data(data)) |
以上实例运行后输出的结果为:
1 | { 'ToUserName' : 'toUser' , 'FromUserName' : 'fromUser' , 'CreateTime' : 1348831860 , 'MsgType' : 'text' , 'Content' : 'this is a test' , 'MsgId' : 1234567890123456 } |