Error locating elements due to mixed namespaces
Brought to you by:
pabigot
Consider the following schema
<xs:import namespace="urn:branch1" schemaLocation="branch1.xsd"/>
<xs:import namespace="urn:branch2" schemaLocation="branch2.xsd"/>
<xs:element name="msg">
<xs:complexType>
<xs:sequence>
<xs:element name="e3" type="xs:string"/>
<xs:element xmlns="urn:branch1" ref="e1"/>
<xs:element xmlns="urn:branch2" ref="e2"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Trying to build the bindings, the following error is shown:
]$ pyxbgen -u root.xsd -m root -u branch1.xsd -m branch1 -u branch2.xsd -m branch2
Exception generating bindings: Unable to locate element referenced by {urn:branch2}e1
Traceback (most recent call last):
File "/tmp/PyXB-1.2.1/scripts/pyxbgen", line 73, in <module>
modules = generator.bindingModules()
File "/tmp/PyXB-1.2.1/pyxb/binding/generate.py", line 2727, in bindingModules
self.__resolveComponentDependencies(reset)
File "/tmp/PyXB-1.2.1/pyxb/binding/generate.py", line 2587, in __resolveComponentDependencies
pyxb.namespace.resolution.ResolveSiblingNamespaces(namespaces)
File "/tmp/PyXB-1.2.1/pyxb/namespace/resolution.py", line 301, in ResolveSiblingNamespaces
if not ns.resolveDefinitions(allow_unresolved=True):
File "/tmp/PyXB-1.2.1/pyxb/namespace/resolution.py", line 222, in resolveDefinitions
resolvable._resolve()
File "/tmp/PyXB-1.2.1/pyxb/xmlschema/structures.py", line 3025, in _resolve
raise pyxb.SchemaValidationError('Unable to locate element referenced by %s' % (ref_en,))
SchemaValidationError: Unable to locate element referenced by
{urn:branch2}e1
It looks like the generator get confused and assign namespaces branch2 to element e1 (defined in branch1).
Funny enough, removing the "e3" from the structure, everything works fine:
<xs:import namespace="urn:branch1" schemaLocation="branch1.xsd"/>
<xs:import namespace="urn:branch2" schemaLocation="branch2.xsd"/>
<xs:element name="msg">
<xs:complexType>
<xs:sequence>
<!-- <xs:element name="e3" type="xs:string"/> -->
<xs:element xmlns="urn:branch1" ref="e1"/>
<xs:element xmlns="urn:branch2" ref="e2"/>
</xs:sequence>
</xs:complexType>
</xs:element>
$ pyxbgen -u root.xsd -m root -u branch1.xsd -m branch1 -u branch2.xsd -m branch2
Python for urn:root requires 3 modules
I was trying to debug the problem further, but without luck till now.
schema t183
Attached the complete schema described above.
Looks like the problem is that the default namespace attribute is updating the namespace map at the sequence element level rather than the element element.
I'll work on a fix; if you can modify the schema the following appears to work around the issue.
commit e2f9ae23fa417cebf7c4ed66732152c499d17c03
Author: Peter A. Bigot <pab@‌>
Date: Wed Dec 26 09:32:06 2012 -0600