Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Validation with multiple schemas using lxml

Tags:

python

lxml

xsd

I'm working with a schema that was built by a third party and I'd like to validate it with lxml. The problem is that such a schema is split over different xsd files, which reference themselves.

For example, a file called "extension.xsd" (which builds upon the "master" schema) has a line like:

<redefine schemaLocation="master.xsd">

If I try to validate it with lxml (parsing, then using XMLSchema then validating another document which I know is valid already), I only get validation using "extension" and not "master": in other words, the validation fails (because in the XML file there are elements only present in "master" and not in "extension").

How can I solve (or work around) this issue? Thanks!

like image 819
Einar Avatar asked Jun 30 '10 08:06

Einar


1 Answers

If lxml doesn't support "redefine", the best option would be to fix it and submit a patch. :)

Failing that, the workaround would be to parse the master.xsd file yourself, and then apply the changes from extension.xsd, and output a single xsd file with the combined schema.

like image 113
tangentstorm Avatar answered Nov 01 '22 04:11

tangentstorm