如何将数据附加到现有的xml SOAP消息中

时间:2016-04-26 07:48:15

标签: python xml soap

我在xml变量中有一条SOAP消息。在此消息中,"令牌"属性是作为uuid动态生成的。类似的东西:

import uuid
uid = uuid.uuid4()
token = uid.hex
xml = '''<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC = "http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd = "http://www.w3.org/2001/XMLSchema" xmlns:xsi = "http://www.w3.org/2001/XMLSchemainstance">
<SOAP-ENV:Body><m:PingRequest xmlns:m = "http://www.derbysoft.com/doorway" **Token="2356"** UserName="test" Password="test" Echo = "Connection Test" />
</SOAP-ENV:Body></SOAP-ENV:Envelope>''' 

所以,我想将这个uuid代码附加到我的xml而不是硬编码。我该怎么追加它?

帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以使用字符串格式:

xml = '''<?xml ... Token="{token}" ... >'''.format(token=token)