Importing two pyxb bindings with conflicting elements into the same namespace

225 Views Asked by At

I have several XSD files from which we have generated python bindings with pyxb (1.2.6). Each of these XSD files use the same namespace. Some of them define elements that have the same name (MyNamedElement). As a result, importing two of such bindings at once yields the following error:

pyxb.exceptions_.NamespaceUniquenessError: my:NAMESPACE: name MyNamedElement used for multiple values in elementBinding

I do not have to use two bindings at the same time, so it would suffice to simply clear pyxb's internal namespace cache if thats possible.

Is there a way to do that, or some other python-magic to circumvent this problem? At the moment, my best idea is to use subprocesses, which perform the import and hopefully loose those again after finishing, s.t. pyxb will not complain.

Another question here on SO has the same error, but it turned out to be caused by a different problem: PyXB: two versions of XSDs with same namespace

1

There are 1 best solutions below

2
BobMcFry On

For those who are having the same problem, here is not the solution but a workaround. If the following imports throw a pyxb.exceptions_.NamespaceUniquenessError

import xml_binding_a
import xml_binding_b

you can add subprocesses that handle the imported modules separately

from multiprocessing import Process

def work_with_binding_a():
    import xml_binding_a
    # ...do more stuff here...

def work_with_binding_b():
    import xml_binding_b
    # ...do more stuff here...


p = Process(target=work_with_binding_a)
p.start()
p.join()

p = Process(target=work_with_binding_b)
p.start()
p.join()