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.

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