Is it possible to remove all namespace prefixes #931
-
In relation to this discussion (#922), is it possible to remove all namespace prefixes? What I'm trying to produce is: 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.
Is there a way to accomplish this? |
Beta Was this translation helpful? Give feedback.
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 There is no easy way to integrate that in the xsdata default writers. |
Beta Was this translation helpful? Give feedback.
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.