OpenLEADR / openleadr-python

Python library for OpenADR
https://openleadr.org/docs
Apache License 2.0
134 stars 52 forks source link

Explore alternatives to the XML-to-dict functionality #17

Open stan-janssen opened 3 years ago

stan-janssen commented 3 years ago

OpenLEADR now does XML parsing that is using xmltodict and a custom postprocessor (normalize_dict). This works well enough that we get very usable dictionaries out of it, and we can plug those same dictionaries into the jinja templating engine to generate perfectly valid XML output.

There is even support for constructing the objects using predefined dataclasses, which makes message creation a little nicer.

There are, however, a few shortcomings that could be addressed:

In short, I'd like to transition to actual objects instead of dicts, and I'd like to explore ways of automating that process.

The avenues I can see are:

The problems I see are:

00javad00 commented 3 years ago

I used to deploy PyXB and generating/validating xml messages directly from xsd schema.

sietse commented 2 years ago

Have a look here, this contains various generated Python schemas to click around in. It uses xsdata to generate a Python schema from the XML schema, using various options.

https://github.com/sietse/compare-schema-generators

IIRC I was disappointed (in December when I tried this) in a few things in the generated schema. But I can only remember one:

I'm pretty happy that there's a way to generate pydantic classes, though. Pydantic guarantees at runtime that the objects it creates conform to schema. It's also checkable with mypy. More guarantees, more better.

More commentary later. Might try other schema generators, too.