I'm trying to create an XML file that needs to be sent to a server, with this format:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sen2="http://www.some_url.com">
<x:Header>
I'm working with Python 3 and the lxml library, but when trying to create the element I get an error.
Test code:
def authSendDataExtraccion():
envelope = etree.Element("x:Envelope")
debug_XML(envelope)
Result:
ValueError: Invalid tag name 'x:Envelope'
How can I use the ":" character in the element and attribute names?
CodePudding user response:
Use an nsmap
to create an element in a namespace:
envelope = etree.Element("Envelope", nsmap={'x': 'http://schemas.xmlsoap.org/soap/envelope/'})