Fraser,

Are you suggesting that this behavior is what all users would want,
and not a unique need, as you mention, for one client of yours?
And, would you want this export behavior for all xs:string members
of all element types in your schema?  If the answer to either of
these questions is "no", then we'd need to come up with some way to
determine or to control when an where to generate the code that does
it.

You mention creating a subclass to the generated class.  You are
already using the "-s" and "--super" command line options, right?
It looks like you are, but I'm not sure.  Then, if you add your
custom code to the subclass module, when you need to regenerate your
code, it might be a little easier to copy your extensions from the
old module to the new one.  Looks like you are doing that, but just
checking ...

With those options, you can do something like the following:

    $ generateDS.py -o libxxxsup.py -s libxxxsub.py --super= libxxxsup 
myschema.xsd

And then you can use libxxxsub.py as a replacement for libxxxsup.py.
libxxxsub.py will automatically import libxxxsup.

About, whether to use pip to install generateds -- That's fine if
you only want to *use* the code.  But, if you want to be able to
submit changes to generateDS, I'd suggest that you fork the project
at Bitbucket and, after making changes to your fork, send me a pull
request.  Here are links to the project at Bitbucket and info about
Bitbucket pull requests, which is very similar to the equivalent
thing at Github, but the interface is different.  It's a Mercurial
repo, so I believe that you will need to use Mercurial rather than
Git.  If you find a way to use git, please let me know.  I actually
prefer Mecurial, but that'd be good to know.

- https://bitbucket.org/dkuhlman/generateds

- 
https://confluence.atlassian.com/bitbucket/pull-requests-and-code-review-223220593.html

- 
https://confluence.atlassian.com/bitbucket/tutorial-learn-about-bitbucket-pull-requests-774243385.html

And, glad you have found generateDS useful.  Thanks for letting me
know.

Dave

On Tue, Jul 31, 2018 at 09:31:00PM +0000, Fraser Hand wrote:
> Hi Dave,
> Thanks for the reply. Just using vanilla generateDS if an element
> is set to none e.g.
> insps = spsclasses.inspections()
> insp = spssubclasses.inspectionTypeSub()
> insp.set_forestManager("NZFyOA")
> insp.set_bioRegion("absjk876%")
> insp.set_diam(None)
> ....
> insp.set_serialNumber(None)
> insp.set_stand("")
> insp.set_inspType("FBS")
> insps.export(outfile,0)
> 
> the diam element will not be written to the output xml
> 
> <inspections>
>     <inspection>
>         <forestManager>NZFyOA</forestManager>
>         <stand></stand>
>         <bioRegion>absjk876%</bioRegion>
>         <inspType>FBS</inspType>
>     </inspection>
> </inspections>
> 
> What I need is this for this particular customer is all elements
> set to None output like:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <inspections>
>     <inspection>
>         <serialNumber />
>         <forestManager>NZFyOA</forestManager>
>         <location />
>         <stand></stand>
>         <siteId />
>         <subSite />
>         <bioRegion>absjk876%</bioRegion>
>         <siteType />
>         <date />
>         <inspector />
>         <hostSpec />
>         <estabYear />
>         <treatment />
>         <stemsPerHa />
>         <diam />
>         <height />
>         <inspType>FBS</inspType>
>         <sampleType />
>         <points />
>         <disorders />
>         <identifications />
>     </inspection>
> </inspections>
> 
> 
> I reread the doc and came up with a solution - to override the
> export function  in the subclass like this - I also made an
> assumption on how you are naming your properties
> 
>     def exportChildren(self, outfile, level, namespace_='', 
> name_='inspectionType', fromsubclass_=False, pretty_print=True):
>         if pretty_print:
>             eol_ = '\n'
>         else:
>             eol_ = ''
>         #based on schema we assume that no _ in field names - filters out 
> generateds stuff
>         for attr, value in self.__dict__.items():
>             print(attr, value)
>             if "_" in attr:
>                 continue
>             else:
>                 if value is not None:
>                     supermod.showIndent(outfile, level, pretty_print)
>                     outfile.write('<{0}>{1}</{0}>{2}'.format(attr,
>                         self.gds_encode(
>                             self.gds_format_string(supermod.quote_xml(value), 
> input_name=attr)),
>                         eol_))
>                 else:
>                     supermod.showIndent(outfile, level, pretty_print)
>                     outfile.write('<{0} />{1}'.format(attr,eol_))
> 
>         if self.points is not None:
>             self.points.export(outfile, level, namespace_, name_='points', 
> pretty_print=pretty_print)
>         if self.disorders is not None:
>             self.disorders.export(outfile, level, namespace_, 
> name_='disorders', pretty_print=pretty_print)
>         if self.identifications is not None:
>             self.identifications.export(outfile, level, namespace_, 
> name_='identifications', pretty_print=pretty_print)
> 
> which does what I want but I lose this the next time the schema is
> updated and the classes regenerated - so updating the source would
> be more elegant.  I take a look at those functions today and see
> what I can do. I have installed via pip so can I updated the
> generateDS.py directly?  Appreciate the reply - thanks very much -
> and it's a super useful library
> Thanks,
> Fraser
> 
> 
> -----Original Message-----
> From: Dave Kuhlman <dkuhl...@davekuhlman.org> 
> Sent: Wednesday, 1 August 2018 6:42 AM
> To: Fraser Hand <fraser_h...@eagle.co.nz>
> Cc: generateds-users@lists.sourceforge.net
> Subject: Re: [Generateds-users] generateds and empty elements
> 
> Fraser,
> 
> Good to hear from you.  Wow.  That version goes back a bit.
> 
> Let me try to repeat back your request so that we're sure I understand it 
> correctly.
> 
> You would like elements of type xs:string to be always exported even if their 
> value is None.
> 
> You might take a look at the code that generates the export functions to see 
> if there is some reasonably easy modification that would give you what you 
> need.  I believe the code that you would be interested in is in 
> `generateDS.py` in the functions `generateExportFn_1` and 
> `generateExportFn_3`.  One of these handles the case where the element is 
> optional (defined with minOccurs="0").
> Look for the test for "StringType".  It looks to me like you should be able 
> to add generation of an `else` clause that gets you what you want.
> 
> Hope this helps.
> 
> Dave
> 
> On Tue, Jul 31, 2018 at 01:51:22AM +0000, Fraser Hand wrote:
> > Hi There,
> > There was a change at Version 1.17a (5/20/2009) where: Modified export 
> > of children of type xs:string so that (1) if None, not exported and 
> > (2) if not None but an empty string, exported (example "<aa></aa>").
> > 
> > Where at 1.16a you wrote out those tags.  Version 1.16a
> > (2/16/2009) Generated export methods now check for empty content and 
> > write out <xx ... /> rather than <xx ...></xx> if empty.
> > 
> > Is there any way to reenable this? Ie get elements with None written 
> > as <element/>
> > 
> > Thanks, Fraser
> > 
> > === www.eagle.co.nz
> > 
> > This email is confidential and may be legally privileged.  If received 
> > in error please destroy and immediately notify us.
> 
> > ----------------------------------------------------------------------
> > -------- 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
> 
> 
> -- 
> 
> Dave Kuhlman
> http://www.davekuhlman.org
> ===
> www.eagle.co.nz 
> 
> This email is confidential and may be legally privileged.
> If received in error please destroy and immediately notify us.

-- 

Dave Kuhlman
http://www.davekuhlman.org

------------------------------------------------------------------------------
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