How can I read multiple xsd strings into xmlschema

757 Views Asked by At

I have multiple XSD strings in my Python program, for example.

xsd1 = '''<?xml version...
   <xs:schema targetNamespace="...
'''
xsd2 = '''...'''

import xmlschema
schema = xmlschema.XMLSchema([xsd1, xsd2]) # it seems xmlschema does not accept such arguments
# then using schema to validate xml files

The two XSD have different target name spaces. How can I read them into xmlschema and validate xml files?

1

There are 1 best solutions below

2
On

Ideally the xmlschema.XMLSchema() constructor would accept a list of file locations and assemble a single XSD model from them all (Eclipse EMF XSD model can do this). But it looks as if xmlschema does not do that trick.

The workaround is to create a single wrapper XSD that imports/includes the other XSDs, and then give the wrapper XSD to xmlschema.