Search code examples
pythonpython-3.xxsdxml-namespacespyxb

PyXB: two versions of XSDs with same namespace


I am implementing a client for the TRIAS APIs v 1.0 and v 1.1 using PyXB. The problem I'm facing is, that both XSD collections have the same namespace with same elements with differing content. So I built two class bindings with pyxbgen for each version. However I now cannot use them both within the same program, since PyXB will throw a pyxb.exceptions_.NamespaceUniquenessError:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/trias/v1_1/trias.py", line 31, in <module>
    import trias.v1_1.siri as _ImportedBinding_trias_v1_1_siri
  File "/usr/local/lib/python3.7/dist-packages/trias/v1_1/siri.py", line 30, in <module>
    import trias.v1_1._nsgroup as _ImportedBinding_trias_v1_1__nsgroup
  File "/usr/local/lib/python3.7/dist-packages/trias/v1_1/_nsgroup.py", line 31, in <module>
    import trias.v1_1._D2LogicalModel as _ImportedBinding_trias_v1_1__D2LogicalModel
  File "/usr/local/lib/python3.7/dist-packages/trias/v1_1/_D2LogicalModel.py", line 93, in <module>
    Namespace.addCategoryObject('typeBinding', 'AbnormalTrafficTypeEnum', AbnormalTrafficTypeEnum)
  File "/usr/lib/python3/dist-packages/pyxb/namespace/__init__.py", line 346, in addCategoryObject
    raise pyxb.NamespaceUniquenessError(self, '%s: name %s used for multiple values in %s' % (self, local_name, category))
pyxb.exceptions_.NamespaceUniquenessError: http://datex2.eu/schema/1_0/1_0: name AbnormalTrafficTypeEnum used for multiple values in typeBinding

How can I use both class bindings within the same program? I cannot edit the source XSD files, since they are not maintained by myself and cannot merge them, since they contain significant differences.


Solution

  • As it turned out, the problem was in a shared sub-package called "Siri 1.4". The trias APIs actually do have different name spaces, but each ship Siri 1.4 as a sub package. Building Siri seperately solved the issue:

    Makefile excerpt:

    dom: | siri trias-1.0 trias-1.1
    
    siri:
        @ echo "Building Siri 1.4."
        @ pyxbgen --schema-root=xsd/trias-xsd-v1.1/siri-1.4 -u siri.xsd -m siri --module-prefix=trias.siri --archive-to-file=xsd/archive/siri.wxs
    
    trias-1.0:
        @ echo "Building TRIAS v 1.0."
        @ pyxbgen --schema-root=xsd/trias-xsd-v1.0 -u Trias.xsd -m trias --module-prefix=trias.v1_0 --archive-path=xsd/archive
    
    trias-1.1:
        @ echo "Building TRIAS v 1.1."
        @ pyxbgen --schema-root=xsd/trias-xsd-v1.1 -u Trias.xsd -m trias --module-prefix=trias.v1_1 --archive-path=xsd/archive