Menu

#24 Incorrect regex from xs:pattern

1.0
open
nobody
None
2021-10-07
2021-10-06
No

I have the following element definition:

<xs:simpleType name="ID_String">
    <xs:restriction base="xs:string">
            <xs:pattern value="[A-Z0-9-]{16}-(ELXP|NGET)-RMT-[0-9]{8}"/>
      <xs:maxLength value="34" />
    </xs:restriction>
  </xs:simpleType>

And in the generated Python code I receive the following regex:

validate_ID_String_patterns_ = [['^[A-Z0-9-]{16}-(ELXP$|NGET)-RMT-[0-9]{8}$']]

Which is definitely incorrect because "ELXP" should not contain end tag.

Example string received in XML: 48X0000000003024-ELXP-RMT-99005821

As a result I have warning:

myfilename.py:739: UserWarning: Value "b'48X0000000003024-ELXP-RMT-99005821'" does not match xsd pattern restrictions: [['^[A-Z0-9-]{16}-(ELXP$|NGET)-RMT-[0-9]{8}$']]
warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_ID_String_patterns_, ))```

Discussion

  • Dave Kuhlman

    Dave Kuhlman - 2021-10-06

    Alexey,

    Trying to diagnose this ...

    I used this XML schema:

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        >
    
        <xs:element name="container" type="containerType"/>
    
        <xs:complexType name="containerType">
            <xs:sequence>
                <xs:element name="time01" type="ID_String"/>
            </xs:sequence>
        </xs:complexType>
    
        <xs:simpleType name="ID_String">
            <xs:restriction base="xs:string">
                <xs:pattern value="[A-Z0-9-]{16}-(ELXP|NGET)-RMT-[0-9]{8}"/>
                <xs:maxLength value="34" />
            </xs:restriction>
        </xs:simpleType>
    
    </xs:schema>
    

    When I generate a module with generateDS.py I get the following pattern:

    validate_ID_String_patterns_ = [['^([A-Z0-9-]{16}-(ELXP|NGET)-RMT-[0-9]{8})$']]
    

    I used the following XML instance document:

    <?xml version="1.0" encoding="utf-8"?>
    <container>
        <time01>48X0000000003024-ELXP-RMT-99005821</time01>
    </container>
    

    If I run the following, I see:

    $ python tmp01sup.py test01.xml
    <?xml version="1.0" ?>
    <container>
        <time01>48X0000000003024-ELXP-RMT-99005821</time01>
    </container>
    

    Can you think of something else I can do in order to track this down?

    I'm using the following:

    Generated Wed Oct  6 16:13:29 2021 by generateDS.py version 2.40.3.
    Python 3.9.5 (default, May 11 2021, 08:20:37)  [GCC 10.3.0]
    

    Are you using an earlier version of gDS, perhaps?

    Or, maybe Python 2.x? I'll check that tomorrow. And, I'll look at your other ticket.

    Dave

     

    Last edit: Dave Kuhlman 2021-10-06
  • Alexey Kolyanov

    Alexey Kolyanov - 2021-10-07

    Dave, my apologies. It seems I mistakenly took an old file generated more than 4 years ago with version 2.26a.
    I've tried again and it works fine with 2.40.3 and Python 3.8.10
    You may close this ticket.

    Great tool by the way, thank you for your work!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.