-
-
Notifications
You must be signed in to change notification settings - Fork 79
Is it possible to remove all namespace prefixes #931
-
In relation to this discussion (#922), is it possible to remove all namespace prefixes?
e.g. what i have now is something similar to
<ns0:foo xmlns:ns0="http..."> <ns0:bar>test</ns0:bar> <ns1:baz>test2</ns1:baz> </ns0:foo>
What I'm trying to produce is:
<foo xmlns="http..."> <bar>test</bar> <baz>test2</baz> </foo>
The ns_map passed into the XmlSerializer.render method is a dict, and the key is the namespace, which means I can at most remove only one namespace with something like the below.
xml_serializer.render( dataclass_obj, ns_map={'': 'foo'} )
Is there a way to accomplish this?
Beta Was this translation helpful? Give feedback.
All reactions
There is no way to know from a top element the namespaces of child elements, unless we do multiple passes, which will slow down the serializer a lot. Not even lxml can do this automatically, but lxml provides https://lxml.de/apidoc/lxml.etree.html#lxml.etree.cleanup_namespaces
You could override https://github.com/tefra/xsdata/blob/main/xsdata/formats/dataclass/serializers/writers/lxml.py in order cleanup the namespaces of the generated self.handler.etree
There is no easy way to integrate that in the xsdata default writers.
Replies: 1 comment
-
There is no way to know from a top element the namespaces of child elements, unless we do multiple passes, which will slow down the serializer a lot. Not even lxml can do this automatically, but lxml provides https://lxml.de/apidoc/lxml.etree.html#lxml.etree.cleanup_namespaces
You could override https://github.com/tefra/xsdata/blob/main/xsdata/formats/dataclass/serializers/writers/lxml.py in order cleanup the namespaces of the generated self.handler.etree
There is no easy way to integrate that in the xsdata default writers.
Beta Was this translation helpful? Give feedback.