On Thu, Mar 26, 2015 at 11:40:49AM +0100, Jan Biel wrote: > Dear Mr. Kuhlman. > > Thanks for your work and effort on building and maintaining the very > useful GenerateDS tool. > > I have a question and would be happy if you could find the time to reply: > > My xsd schema uses elements that are both optional and have a default value, > e.g. > <xs:element name="Value" type="xs:float" default="0.0" minOccurs="0"/> > > When reading and saving a corresponding xml file where the optional > element is missing, GenerateDS will always add the missing element, > using the default value. Is this behavior desired? If the element > was not there before, shouldn't it be omitted when the document is > saved? If this behaviour is intended, would you know of a way to > preserve the original state of the document? I found a workaround > by manually replacing the default values by ‘None’ in the generated > python code: > > def __init__(self, Id=0, Value=0.0): > def __init__(self, Id=0, Value=None): > > However, since the document is fairly large and there would be many > occurrences, I was hoping there was a better way to automate this.
So, if I understand you correctly, you are saying that in the generated method exportChildren, for an element with a default value, instead of generating: if self.integer_value is not None: if self.string_value is not None: We should instead generate: if self.integer_value != 27: # or some default integer value if self.string_value != "some default string value": Etc. And, the generated function hasContent_ would also need to be changed in a similar way. That sounds right to me. Do you agree? Or, is there some corner case that we have to consider? Unfortunately, the code in generateDS.py will need to be modified in a number of places, because it has to handle types xs:string, xs:integer, xs:date, xs:float, etc. So, this change will take me a bit of time. I'll see what I can do. > > Thanks again for your work! You are welcome. Glad it is of use. Dave -- Dave Kuhlman http://www.davekuhlman.org ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users