Re: [Generateds-discuss] Export of an enumerated string restriction attribute with a default value
Brought to you by:
dkuhlman
|
From: Dave K. <dku...@da...> - 2023-05-17 22:48:55
|
Andrii,
I took a little time for me to find those solutions: (1) the
"--always-export-defaults" command line option and (2)
`use="required"` in the XML schema.
And, now I've had time to test them. They both seem to work,
depending on what you want them to do.
1. The "--always-export-defaults" command line option affects all
attributes (and perhaps some other things, too.
2. The `use="required"` in the XML schema can be applied more
selectively to specific attributes declarations.
I've attached files that you can use to run a test. You might have
to edit `test.sh` a bit.
Here is the results of running a test:
$ ./test.sh
+ python generateDS.py -f -o tmp01sup.py test01.xsd
+ python generateDS.py -f -o tmp02sup.py --always-export-default
test01.xsd
+ python generateDS.py -f -o tmp03sup.py test02.xsd
+ python tmp01sup.py test01.xml
<?xml version="1.0" ?>
<collection>
<item>
<ident>item01</ident>
</item>
<item units="TB">
<ident>item02</ident>
</item>
</collection>
+ python tmp02sup.py test01.xml
<?xml version="1.0" ?>
<collection>
<item units="GB">
<ident>item01</ident>
</item>
<item units="TB">
<ident>item02</ident>
</item>
</collection>
+ python tmp03sup.py test01.xml
<?xml version="1.0" ?>
<collection>
<item units="GB">
<ident>item01</ident>
</item>
<item units="TB">
<ident>item02</ident>
</item>
</collection>
Hope this helps. Let me know when you have more questions.
Dave
Quoting Andrii Iudin <an...@eb...>:
> Dear Dave,
>
> Please could you help with writing out to XML an enumerated string
> restriction attribute with a default value? It looks like this:
> <xs:attribute default="GB" name="units">
> <xs:simpleType>
> <xs:restriction base="xs:string">
> <xs:enumeration value="TB"/>
> <xs:enumeration value="GB"/>
> <xs:enumeration value="MB"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:attribute>
>
> When writing out and the value is set to "GB", no units are output
> into the XML.
>
> It appears that the skip is happening in the following generated logic:
> def _exportAttributes(self, outfile, level, already_processed,
> namespaceprefix_='', name_='datasetSizeType'):
> if self.units != "GB" and 'units' not in already_processed:
> already_processed.add('units')
> outfile.write(' units=%s' %
> (self.gds_encode(self.gds_format_string(quote_attrib(self.units),
> input_name='units')), ))
>
> At this point in code already_processed is just an empty set().
>
> Is there any switch or change in schema that we might do to ensure
> "GB" units are added even if the value is the same as the default one?
>
> Many thanks and best regards,
> Andrii
>
>
> _______________________________________________
> Generateds-discuss mailing list
> Gen...@li...
> https://lists.sourceforge.net/lists/listinfo/generateds-discuss
--
Dave Kuhlman
http://www.davekuhlman.org
|