On Sun, Oct 23, 2016 at 01:56:37PM -0700, Dave Kuhlman wrote: Pietro, A few comments are below.
> Hello Dave, > > Thanks for your answer, I replied inline. > > I've done some work on this. And, possibly, I have a fix. What the > > fix does is to check each child element to determine if it has a > > sibling with the same name. If there is a sibling with the same > > name, this fix deletes that element and marks this element as > > self.maxOccurs=2 (effectively maxOccurs="unbounded"). > > > > Just to clarify, here you're talking about the XML schema right? I looked > at the code but I still need to understand it better and try it. > As far as I understood, this fix would "flatten out" the > "sequence>author+choice(author, > cooperation)" structure, by turning it into an unbounded list of authors, > in case other elements are found. > Why then `maxOccurs=2`? Shouldn't it take the `maxOccur` value of the ` > choice` tag + 1? Good point. But, I believe that if maxOccurs is anything greater that 1 or is "unbounded", then it generates the same code, specifically a list and support for it. So, I have to think about the "+ 1" idea. > > > OK. So, now that we have what might be a fix, we need to ask: Should > > we really make this fix? Is the snippet of the XML schema that you > > sent (see below) legal? > > > > According the XSD validator at http://www.utilities-online. > info/xsdvalidation/, it is. Thanks. That reasures me that I'm not trying to slay an *imaginary* dragon. (OK. I admit that's overly dramatic, but you see what I mean.) I need to learn more about this use of minOccurs/maxOccurs on an enclosing <xsd:choice>. I'm taking Peter Berlin's hint (in another message on the list) that I should test with the FpML schemas. So, I'm trying to do some testing with FpML (www.fpml.org) because I feel that would be a very rigorous test. In the schemas I find this fragment: <xsd:choice maxOccurs="unbounded"> <xsd:element name="tradeId" type="TradeId" /> <xsd:element name="versionedTradeId" type="VersionedTradeId"> </xsd:element> </xsd:choice> But, the code generated from this schema is confused about whether tradeId is a singleton or a list. It causes an exception. Something is certainly wrong. > > > then why couldn't you write this: > > > > Because in XML the elements are unique. You are defining two `author` > elements which declare different types. > Indeed, the validator rejects the schema in your example. > In my example I'm referencing the same `<author>` on two different levels. > > > > where the "author" child elements have two different types but the > > same name. I don't think it makes much sense for generateDS.py to > > handle that. It would require generating a class with to member > > data items with the same name and different types. > > > > I agree, there is no reason why it should support an illegal schema. I'm glad that this problem is restricted in that way. More later. Dave > > Actually, there > > were a couple of other schemas in the unit tests that were > > questionable and that this fix revealed. > > > > Good to know that the problem was not just limited to this corner case! > > > > By doing this (the above fix plus a warning), we'd have these > > benefits: > > What do you think? > > > > This makes me wonder: wouldn't it be better to validate the schema, at > least partially, and trigger an exception in case of invalid code? > The warning is likely to be ignored if the schema is illegal, and in case > of a legal schema is misleading. > > I will read the code more in depth later and get back to you once I tried > it. > > Pietro > > > > > > > A patch is attached. > > > > Sorry for being so wordy. It helps me think these things through. > > > > Dave > > > > -- Dave Kuhlman http://www.davekuhlman.org ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users