最近臨時工作要生成xml報名,通過MQ接口發(fā)送。簡單小程序。
自增長拼成xml報文
Test_001.py
# encoding=utf-8import time orderId = ''s1= "/n"#for ID in range(1,5): item1 = "<item>" + / "<orderID>" + str(ID) + "</orderID>" + / "<time>" + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + "</time>" + / "</item>" orderId+=item1messge = "<MbfBody>" + orderId + "</MbfBody> "print(messge)另外一種狀態(tài)
#encoding=utf-8 # str=input("輸入字段:")str='lxs,hqq,lj,xc'List=str.split(',') # str_xml=input("輸入替換的模板:")str_xml='<step id="xml_set_xml_value" comment="value" isrun="true"><param id="xml">VAR_XML</param><param id="xpath">//MbfBody/value</param><param id="value">COLUMN(VALUE,y)</param></step>' #列表追加,回車成多行def add_xml(L): xml_list=[] s1= '/n' #回車換行符 for value in L: VAULE=value.upper() xml= str_xml.replace('value',value,2).replace('VALUE',VAULE,1) #替換模板中的值為列表中的值,小寫兩次,大寫一次 xml_list.append(xml) xml_str=s1.join(xml_list) #list 更新成str return xml_str #字符串追加,一行# def add_xml(L):# xml_list=''# for value in L:# VAULE=value.upper()# xml= str_xml.replace('value',value,2).replace('VALUE',VAULE,1) #替換模板中的值為列表中的值,小寫兩次,大寫一次# xml_list+=xml# # xml_str=s1.join(xml_list) #list 更新成str# return xml_list test=add_xml(List)print(test)以上這篇對python 生成拼接xml報文的示例詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答