xml基础(二)

有了上面的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

 

posted on 2019-10-26 20:21  龙贝勒  阅读(145)  评论(0编辑  收藏  举报