Re: [Generateds-discuss] Export of an enumerated string restriction attribute with a default value
Brought to you by:
dkuhlman
From: Andrii I. <an...@eb...> - 2023-05-18 08:50:41
|
Hi Dave, Thank you for the fast response and the suggestions! I like the flexibility of use="required", but I get this warning: [Xerces] src-attribute.2: : The property 'default' is present in attribute 'units', so the value of 'use' must be 'optional'. Here https://www.w3.org/TR/xmlschema-1#d0e2403 (3.2.3) it says "If default and use are both present, use must have the ·actual value· optional." Perhaps, for the same of compliance we will stick with the always-export-default flag. Thank you again for the help! Best regards, Andrii On 17/05/2023 23:48, Dave Kuhlman wrote: > 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 > > > |