I've made a fix. The problem was that for simple types that are a restriction on (extension of) another simple type, we needed to key off of the base simple type. So, for example in the case you reported, we needed to find out that the attribute was a `float` rather than a `degree`.
I've pushed this fix to the Bitbucket repository: https://dkuhl...@bitbucket.org/dkuhlman/generateds It's a one line fix. And, here is a diff: diff -r 93733afec7e9 generateDS.py --- a/generateDS.py Thu May 23 15:32:11 2019 -0700 +++ b/generateDS.py Sun Jun 16 09:24:46 2019 -0700 @@ -235,7 +235,7 @@ # Do not modify the following VERSION comments. # Used by updateversion.py. ##VERSION## -VERSION = '2.32.0' +VERSION = '2.32.1' ##VERSION## BaseStrTypes = six.string_types @@ -2672,7 +2672,7 @@ attrDef = attrDefs[key] name = attrDef.getName() cleanName = mapName(cleanupName(name)) - attrType = attrDef.getType() + attrType = attrDef.getBaseType() wrt(" if self.%s is not None:\n" % (cleanName, )) if (attrType in StringType or attrType in IDTypes or Please let me know if this fix does not work for you. And, thanks again for reporting it and providing the test case. That helped quite a bit. Dave On Wed, Jun 12, 2019 at 12:55:09PM +0200, Van Huynh Le wrote: > Hi, > > I report an issue with on bitbucket, but I think the discussion is more > active here. Please ignore this email if this is not the right place to > report bug. > > --- Copied from Bitbucket --- > > Thanks for the greate package. I’m using generateDS to create Python > bindings for XML schema, and it works pretty well. I have a small issue > though: the method to_etree of the generated class does not handle > attributes well. > > > Reproduction of the issue: > > The following schema describes an element “Rotation“ with two children > (pitch, yaw) and one attribute (roll). All these children and attributes are > floats between 0 and 360. > > <?xml version="1.0" encoding="UTF-8"?> > <schema xmlns="http://www.w3.org/2001/XMLSchema" > xmlns:tns="http://www.example.org/Rotation/" > targetNamespace="http://www.example.org/Rotation/" > > > <element name="Rotation"> > <complexType> > <sequence> > <element name="pitch" type="tns:degree"></element> > <element name="yaw" type="tns:degree"></element> > </sequence> > <attribute name="roll" type="tns:degree" > use="required"></attribute> > </complexType> > </element> > > > <simpleType name="degree"> > <restriction base="float"> > <minInclusive value="0"></minInclusive> > <maxInclusive value="360"></maxInclusive> > </restriction> > </simpleType> > </schema> > > Then I generate the python class with: > > generateDS -o rotation.py -f -q --preserve-cdata-tags --export="write etree" > Rotation.xsd > > The issue is that the to_etree method of the generated class throws an > error: > > import rotation > > obj = rotation.Rotation(roll=1, pitch=2, yaw=3) > obj_etree = obj.to_etree() # Exception here: TypeError: Argument must be > bytes or unicode, got 'float' > > I think the reason is that the generated code does not convert the attribute > to string first (lines 935-936): > > if self.roll is not None: > element.set('roll', self.roll) # Exception here > > > I’m missing something or is this a bug in generateDS? > > Kind regards, > > Van Huynh Le > > > > <?xml version="1.0" encoding="UTF-8"?> > <tns:Rotation roll="0.0" xmlns:tns="http://www.example.org/Rotation/" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.example.org/Rotation/ Rotation.xsd "> > <pitch>0.0</pitch> > <yaw>0.0</yaw> > </tns:Rotation> > _______________________________________________ > generateds-users mailing list > generateds-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/generateds-users -- Dave Kuhlman http://www.davekuhlman.org _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users