Dear Dave,

Thank you for the promptly implemented patch. I have tested it and the result with the switch "--export-when-default" does not fail xmllint validation on framesPerImage anymore.

I have discussed this with my colleagues and your suggested alternative looks reasonable. If the element has more than zero minOccurs, than it has to be exported with the default value, otherwise if the minOccurs is zero, then it can be omitted.

Best regards,
Andrii

On 29/11/2017 23:59, Dave Kuhlman wrote:
Andrii,

I've made a fix.  It's attached to a separate email.  I've done some
light testing and this change seems to work as I expect.  But, maybe
what I expect is wrong.

However, before using that new version, please read my comments
below.  I'm wondering whether I've made the correct fix.  See
below.

Following your hint, I have added a new command line option to
generateDS.py: --export-when-default

When you use this option, generateDS.py will now generate code that
exports children, even when a child's value is equal to the default
value specified in the XML schema.

Am I correct that we should apply this new behavior to child
elements, but *not* to attributes?  I did a little reading on this
and it appears that an attribute with a default value is optional
but that a child element with a default value and minOccurs greater
than zero is not.

If the above is correct, perhaps instead of a new command line
option, this new behavior (not omitting the child element) should
always be done, or at least it should be the default and the new
flag should generate code that has the old behavior (exports the
child element when the value equals the default).

So, here is an alternative:

For child elements defined with a default value, generate code that
(a) always exports the child element if it's minOccurs is greater
than zero and (b) if its minOccurs is zero (it is optional) exports
it only if its value is different from the default.

If we do this, then we can get rid of the --export-when-default
option in the patched version I'm sending.

What do you think?

Dave

On Tue, Nov 28, 2017 at 11:28:39AM +0000, Andrii Iudin wrote:
Dear Dave,

We are having a problem with exporting an element with a set default value.
The element in question is
<xs:element name="framesPerImage" type="xs:integer" default="1">
     <xs:annotation>
         <xs:documentation>Normally = 1.
Relevant for multi-frame direct electron detectors.</xs:documentation>
     </xs:annotation>
</xs:element>

It seems to be exported only when its value is not equal to the default one
if self.framesPerImage != 1:
     showIndent(outfile, level, pretty_print)
outfile.write('<%sframesPerImage>%s</%sframesPerImage>%s' % (namespace_,
self.gds_format_integer(self.framesPerImage, input_name='framesPerImage'),
namespace_, eol_))

As a result, xmllint fails to validate the exported XML since it is missing
framesPerImage element.

Please could you tell if there is a switch that could force exports of
elements if they have a default value? The relevant code seems to be
starting at line 2080
         if default is None:
             wrt('%s        if self.%s is not None:\n' % (fill, mappedName,
))
         else:
             wrt('%s        if self.%s != %s:\n' % (
                 fill, mappedName, default, ))

Many thanks and best regards,
Andrii

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to