Open stan-janssen opened 3 years ago
I used to deploy PyXB and generating/validating xml messages directly from xsd
schema.
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:
str
or a NewType
; 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.
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:
xmltodict
and another bylxml
preflight_message
) that validates object contents before XML serialization, which should maybe be handled inside objects.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:
lxml.objectify
APIpyxmpp
's XSO model.The problems I see are: