> Dear all
>
> I had the following problem:
>
> In an XSD schema I have an element contourLevel that takes a
> float value and has an attribute defined as follows:
>
> <xs:element name="contourLevel" minOccurs="0">
> <xs:complexType>
> <xs:simpleContent>
> <xs:extension base="xs:float">
> <xs:attribute name="source" type="xs:string" use="optional"/>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
> </xs:element>
>
> An example XML snippet is as follows:
> <contourLevel source="author">0.71</contourLevel>
>
> The problem that I have is when the value is zero and write out the
> contourLevel element using a generateDS generated object. What I
> get is:
>
> <contourLevel source=author/>
>
> My expectation is:
>
> <contourLevel source="author>0</contourLevel>
Ardan,
Yes, this seems like a bug to me.
Your change (below) seems like a good one to me. I've patched that
into my repository. It will be uploaded soon.
Thanks for your fix.
However, this mystified me for awhile. I parsed and exported a file
(see attached schema and XML instance doc) and could not reproduce
the problem, at first. Then I found out that when the generated
code parses the instance doc, it saves the value as a string (e.g.
"0.0"). It's only after you set the value to *numeric* zero, that
the problem appears.
Which makes me wonder whether the value of something defined as
xs:simpleContent that extends type xs:float (or xs:integer or other
numeric types) should be converted to a Python int or float by the
build method. But, that might cause disruption for existing
applications and users. So, I suppose that is a change for another
time, if at all.
What do you think?
Thanks again.
Dave
>
> Looking through the file: generateDS.py
> I found that this was because of the following code in the following
> method: def generateHascontentMethod(wrt, prefix, element) the code:
>
> if element.getSimpleContent() or element.isMixed():
> if not firstTime:
> wrt(' or\n')
> firstTime = False
> wrt(' self.valueOf_)
>
> I modified to:
>
> if element.getSimpleContent() or element.isMixed():
> if not firstTime:
> wrt(' or\n')
> firstTime = False
> wrt(' 1 if type(self.valueOf_) in [int,float] else
> self.valueOf_)
>
> In this was a zero valued number is still considered as content.
>
> I was wondering if this was an acceptable solution to integrate into
> the main distribution?
>
> The version I am working with is 2.17a0
> Many thanks and best wishes
>
--
Dave Kuhlman
http://www.davekuhlman.org
------------------------------------------------------------------------------
_______________________________________________
generateds-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/generateds-users