madpah / serializable

Pythonic library to aid with serialisation and deserialisation to/from JSON and XML.
https://py-serializable.readthedocs.io/
Apache License 2.0
4 stars 4 forks source link

feat: reduce xml bloat, remove xml-namespace ID from elements and sttributes #22

Closed jkowalleck closed 11 months ago

jkowalleck commented 1 year ago

.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.

requires #11 & #12

jkowalleck commented 1 year ago

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
        )
jkowalleck commented 11 months ago

feature is possible to implement downstream, and might already e availave via convinience-methods.

see https://github.com/madpah/serializable/pull/20