xsdata icon indicating copy to clipboard operation
xsdata copied to clipboard

Generate a different default Envelope namespace (not soapenv:Envelope xmlns="")

Open atlantis-dsf opened this issue 1 year ago • 1 comments

Sorry if this has a simple fix just using Config, but I can't find it anywhere

when parsing (my?) WSDLs xsdata generates this

class ExampleServicePortTypeServiceAction:
    style = "document"
    required = "true"
    location = "http://unspecified"
    transport = "http://schemas.xmlsoap.org/soap/http"
    soap_action = "http://example.com/soap/conn/ExampleService/v2.5/ServiceAction"
    soap_action_required = "false"
    input = ExampleServicePortTypeServiceActionInput
    output = ExampleServicePortTypeServiceActionOutput

and it sets the value for the transport attribute of port types to "http://schemas.xmlsoap.org/soap/http" (let's call it the default namespace)

Also, the XmlSerializer generates an xml string that starts with

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

I need to at least override the default namespace! Can I do this on generation? Or do I need to do this in the serializer? I'm not using replacements/substitutions/global_ns or ns_maps of any kind, bc they end up breaking the document and the parser throws an error (I use the parser to verify that I didn't f'up the document too much on serialization)

The nice-to-have would be to be able to override the "default" "soapenv" with my choice of ns-shorthand

Thank you very much for this great library! Best David

Specs

Python 3.11.2

(venv) C:\projects\xsdata-generate>pip show xsdata
Name: xsdata
Version: 23.8
Summary: Python XML Binding
Home-page:
Author:
Author-email: Christodoulos Tsoulloftas <[email protected]>
License: MIT
Location: C:\projects\py\venv\Lib\site-packages
Requires: typing-extensions
Required-by:

atlantis-dsf avatar Jan 11 '24 00:01 atlantis-dsf

Hi @atlantis-dsf on the serializer you can override the prefixes and set a default one

https://xsdata.readthedocs.io/en/latest/xml.html#serialize-xml-with-default-namespace

print(serializer.render(books, ns_map={None: "urn:books"}))
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns="urn:books">
  <book xmlns="" id="bk001" lang="en">
    <author>Hightower, Kim</author>
    <title>The First Book</title>
    <genre>Fiction</genre>
    <price>44.95</price>
    <pub_date>2000-10-01</pub_date>
    <review>An amazing story of nothing.</review>
  </book>
</books>

tefra avatar Jan 11 '24 04:01 tefra