Van Huynh Le,

Thank you for reporting this problem.

Yes, this is a good place to discuss generateDS issues.

It's been a while since I've worked on the to_etree stuff.

I'll take a look.

Thank you for providing the detailed description and the sample code
to reproduce the problem.

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

Reply via email to