xml_data() xml轉(zhuǎn)字典
xml_data() 接收一個參數(shù),第一個參數(shù)為要轉(zhuǎn)換的xml數(shù)據(jù)
以下是 xml_data() 的語法:
xml_data(data)
● data [類型]:需要轉(zhuǎn)字典的xml數(shù)據(jù)。
返回一個dict類型的數(shù)據(jù)
以下展示了使用 xml_data() 的實(shí)例:
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))
以上實(shí)例運(yùn)行后輸出的結(jié)果為:
{'ToUserName': 'toUser', 'FromUserName': 'fromUser', 'CreateTime': 1348831860, 'MsgType': 'text', 'Content': 'this is a test', 'MsgId': 1234567890123456}