[xsd-users] <choice> abuse

Ray Lischner rlischner at proteus-technologies.com
Wed Mar 14 10:28:37 EDT 2007


Upon further reflection, I realize that I was wrong. Code Synthesis does not enforce other schema restrictions, such as maxOccurs. There is no reason to treat <choice> differently or specially.
--
Ray Lischner, Proteus Technologies

________________________________

From: xsd-users-bounces at codesynthesis.com on behalf of Ray Lischner
Sent: Mon 3/12/2007 11:26 AM
To: xsd-users at codesynthesis.com
Subject: [xsd-users] <choice> abuse



The implemenentation of <choice> has the potential for abuse. Suppose I have a schema with the following:
<complexType name="X">
  <choice>
    <element name="a" type="int"/>
    <element name="b" type="float"/>
    <element name="c" type="string"/>
  </choice>
</complexType>

The generated class X has three optional members: a, b, and c. The problem is that I can set all three members:

X x;
x.a(20);
x.b(3.14);
x.c("hello");

with the nonsensical result that the "choice" has all three values, not only one. I wish the code were more resilient to programmer error. Calling x.b(2.718) should result in a call to x.a().reset() and x.c().reset().

Or the implementation of <choice> could switch to a union, with a generated enumeration to specify which union member is valid.

Meanwhile, I'm open to suggestions for the best way to ensure that programmers do not inadvertently create invalid objects.
--
Ray Lischner, Proteus Technologies





More information about the xsd-users mailing list