Python - working with xml/lxml/objectify/schemas, datatypes, and assignments

Dieter Maurer dieter at handshake.de
Wed Jan 4 09:42:28 EST 2023


aapost wrote at 2023-1-3 22:57 -0500:
> ...
>Consider the following:
>
>from lxml import objectify, etree
>schema = etree.XMLSchema(file="path_to_my_xsd_schema_file")
>parser = objectify.makeparser(schema=schema, encoding="UTF-8")
>xml_obj = objectify.parse("path_to_my_xml_file", parser=parser)
>xml_root = xml_obj.getroot()
>
>let's say I have a Version element, that is defined simply as a string
>in a 3rd party provided xsd schema
>
><xs:element name="Version" type="xs:string" minOccurs="0">

Does your schema include the third party schema?

You might have a look at `PyXB`, too.
It tries hard to enforce schema restrictions in Python code.


More information about the Python-list mailing list