#183 Error locating elements due to mixed namespaces

PyXB 1.2.2
closed
None
fixed
Generation Model
minor
PyXB 1.2.1
defect
2012-12-26
2012-12-21
jmaroto
No

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.

1 Attachments

Discussion

  • jmaroto

    jmaroto - 2012-12-21

    schema t183

     
  • jmaroto

    jmaroto - 2012-12-21

    Attached the complete schema described above.

     
  • Peter A. Bigot

    Peter A. Bigot - 2012-12-21
    • status changed from new to accepted

    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.

        <xs:element name="msg">
            <xs:complexType>
                <xs:sequence xmlns:b1="urn:branch1" xmlns:b2="urn:branch2">
                    <xs:element name="e3" type="xs:string"/>
                    <xs:element ref="b1:e1"/>
                    <xs:element ref="b2:e2"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
     
  • Peter A. Bigot

    Peter A. Bigot - 2012-12-26
    • status changed from accepted to closed
    • resolution set to fixed

    commit e2f9ae23fa417cebf7c4ed66732152c499d17c03
    Author: Peter A. Bigot <pab@‌>
    Date: Wed Dec 26 09:32:06 2012 -0600

    trac/183: Error locating elements due to mixed namespaces

    Never apply namespace directives to the current context: they belong to a
    subsequent element. Use the new context when entering an element, and
    discard it when leaving the element to which it applies. Only create a new
    context when it is necessary to do so.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks