feat: reduce xml bloat, remove xml-namespace ID from elements and sttributes
jkowalleck opened this issue · comments
.to_xml()
currently returns like
<?xml version='1.0' encoding='utf-8'?>
<my:book xmlns:my="http://the.phoenix.project/testing/defaultNS" my:isbn_number="978-1942788294">
<my:id>f3758bf0-0ff7-4366-a5e5-c209d4352b2d</my:id>
</my:book>
the defaultNS can be just set properly, and hen the NS-id can be omitted.
like
<?xml version='1.0' encoding='utf-8'?>
<book xmlns="http://the.phoenix.project/testing/defaultNS" isbn_number="978-1942788294">
<id>f3758bf0-0ff7-4366-a5e5-c209d4352b2d</id>
</book>
using a defaultNS would make the resulting documents smaller, but still equal.
ElementTree.tostring()
's default_namespace
parrameter is not available before py38
one could register the namespace as an empty-string-id ...
but if this is done, then the existence of the NS must ceckecked, it must not be overridden.
and the registration must be reverted, after all is done ...
ElementTree.register_namespace('', xmlns)
ElementTree.tostring(
the-thing, method='xml',
encoding='unicode',
# default_namespace=xmlns # not avialable in py37, ... need to register NS globally
)
feature is possible to implement downstream, and might already e availave via convinience-methods.
see #20