xml基础
Posted ichbinhere
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于xml基础的主要内容,如果未能解决你的问题,请参考以下文章
xml Eclipse模板(代码片段)检查参数并最终抛出IllegalArgumentException
从 XML 声明片段获取 XML 编码:部分内容解析不支持 XmlDeclaration