Reputation: 1063
I have a SOAP message in xml variable. In this message, the "Token" attribute is dynamically generated as uuid. Something like:
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>'''
So, I want to append this uuid code to my xml instead of hardcoding it. How can I append it?
Help would be appreciated.
Upvotes: 0
Views: 81
Reputation: 59425
You can use string formatting:
xml = '''<?xml ... Token="{token}" ... >'''.format(token=token)
Upvotes: 1