hexBinary length restriction fails incorrectly

Help
2013-09-18
2013-09-19
  • Sebastian Haas
    Sebastian Haas
    2013-09-18

    Hi!

    I have an XML schema which defines a datatype based on hexBinary with a length restriction like so:

    <xs:attribute name="Color" use="optional">
        <xs:simpleType>
            <xs:restriction base="xs:hexBinary">
                <xs:length value="4"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:attribute>
    

    This is then used in a tag attribute in an XML document like this:

    <Font ID="Arial" Color="FFFFFFFF" Weight="normal" Size="40">
    

    Where the Color value should evaluate to a length of 4. However on loading the XML document, I get the following error:

    Type <class 'libdcp.xsd.dcpschema.smpte_subtitle.STD_ANON_9'> length constraint violated by value FFFFFFFF
    

    I checked the generated pyxb module and STD_ANON_9 is indeed the "Color" datatype.

    Also:

    >>> from binascii import unhexlify
    >>> len(unhexlify('FFFFFFFF'))
    4
    

    It seems to me that this might be a bug in pyxb (I didn't find anything related to this in the Trac, so I'm posting this here.)

     
  • Peter A. Bigot
    Peter A. Bigot
    2013-09-18

    It is a bug, though not with the restriction length. In an attribute context the constructor is bypassing the hexBinary functions that convert the lexical space value. Should be fixed later today.

     
  • Peter A. Bigot
    Peter A. Bigot
    2013-09-18

    Confirmed, bug recorded as trac/216, and patch committed in next branch. This will be in PyXB 1.2.3 due to be released today or tomorrow.

    Good catch. Thanks.

     
  • Sebastian Haas
    Sebastian Haas
    2013-09-19

    Awesome, thanks for the quick fix :)