码迷,mamicode.com
首页 > 其他好文 > 详细

xml基础(二)

时间:2019-10-26 20:52:00      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:ali   min   text   nal   color   cas   imp   can   response   

有了上面的xml基础了,可以用Python生成相应的vxt文件了。

直接上代码:

import xml.etree.ElementTree as ET
#生成canmsg元素 def canmsg_element(id_input,bus_input): canmsg_ele=ET.Element("canmsg",{"id":id_input,"bus":bus_input}) return canmsg_ele
#生成signalref元素 def signalref_element(name_input,refname_input): signalref_ele=ET.Element("signalref",{"name":name_input,"refname":refname_input}) return signalref_ele
#生成request元素 def request_element(id_input,bus_input): request_ele=ET.Element("request") canmsg_ele=canmsg_element(id_input,bus_input) request_ele.append(canmsg_ele) return request_ele
#生成response元素 def response_element(id_input,bus_input,signalref_name_input,refname_input): response_ele=ET.Element("response") canmsg_ele=canmsg_element(id_input,bus_input) signalref_ele=signalref_element(signalref_name_input,refname_input) canmsg_ele.append(signalref_ele) response_ele.append(canmsg_ele) return response_ele
#生成requestresponsecheck元素 def requestresponsecheck(timeout,mintime,id_request,bus_request,id_response, bus_response,signalref_name,refname): requestresponsecheck_ele=ET.Element("requestresponsecheck",{"timeout":timeout,"mintime":mintime}) request_ele=request_element(id_request,bus_request) response_ele=response_element(id_response,bus_response,signalref_name,refname) requestresponsecheck_ele.append(request_ele) requestresponsecheck_ele.append(response_ele) return requestresponsecheck_ele
#生成cansignal元素 def cansignal(name,msg,bus,text_input): cansignal_ele=ET.Element(‘cansignal‘,{‘name‘:name,"msg":msg,‘bus‘:bus}) cansignal_ele.text=text_input return cansignal_ele
#生成initialize元素 def initialize(title_init,wait,name,msg,bus,text): initialize_ele=ET.Element(‘initialize‘,{‘title‘:title_init,‘wait‘:wait}) cansignal_ele=cansignal(name,msg,bus,text) initialize_ele.append(cansignal_ele) return initialize_ele
#生成testcase元素 def testcase(title,ident,title_init,wait,name,msg,bus,text_from,text_to): testcase_ele=ET.Element(‘testcase‘,{‘title‘:title,‘ident‘:ident}) initialize_from=initialize(title_init,wait,name,msg,bus,text_from) initialize_to=initialize(title_init,wait,name,msg,bus,text_to) testcase_ele.append(initialize_from) testcase_ele.append(initialize_to) return testcase_ele

 

xml基础(二)

标签:ali   min   text   nal   color   cas   imp   can   response   

原文地址:https://www.cnblogs.com/ichbinhere/p/11745358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!