1

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?

CodeMonkey
  • 22,825
  • 4
  • 35
  • 75
Edmund
  • 697
  • 6
  • 17

1 Answers1

1

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.

kimbert
  • 2,376
  • 1
  • 10
  • 20
  • thank you @kimbert. Is there a way to import/include other xsd strings considering i am using python string instead of files. – Edmund Jul 23 '20 at 19:22
  • https://xmlschema.readthedocs.io/en/latest/usage.html#create-a-schema-instance . Finding and reading documentation is a skill worth acquiring :-) – kimbert Jul 23 '20 at 23:40