Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Force validation when loading a xml #665

asrenzo started this conversation in General
Discussion options

Hi,

Sounds like I'm missing something.
I used xsdata cli to generate some python code from an existing xsd.
Everything seems OK and required data seem to be generated accordingly to xsd definition.

When parsing a conform file (xmllint gives no validation error), no error. The object is created with as imagined

When parsing an invalid file (xmllint raises a validation error), there is no error either. The object is created with missing required informations.

I guess I'm missing something but what ?

Regards,

Laurent

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Hi @asrenzo have a look here

Basically in dataclasses field with default values have to be declared before any other field, but xsdata relies on the field ordering for the serialization. For that reason the generator marks all fields as Optional[...] despite what you see in the field metadata={"required": true}

That part of the metadata currently is completely imformative for the developer.

In Python 3.10 dataclasses introduced a new directive kw_only that resolves the above limitation and xsdata handling. Read more

You must be logged in to vote
1 reply
Comment options

I have the same question: how to enforce XML elements' and attributes' content validation (for example by regex or by string/integer type).
Unfortunately the both links today lead to incorrect locations.

Could you give us updated links? Could you recommend some approach to XML content validation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /