ISSUE-14: xs:default handling by generated types

ISSUE-14: xs:default handling by generated types

http://www.w3.org/2005/06/tracker/databinding/issues/14

Raised by:  Everyone
On product: Basic

"""
This is a specific problem with xs:default and type
generators/serializers that can potentially be merged with ISSUE-7
(minOccurs="0" and nillable="true").  

The xs:default attribute on an element declaration is a feature of XML
Schema that is meant to be applied by a schema validation process.
Default values are inserted into the post-schema-validated-Infoset
(PSVI) *only* if the element is present in the input document with empty
content (and without an xsi:nil="true" attribute).  By now, virtually
all schema validation tools execute this rule correctly.  However, many
type generators, including .NET 2.0*, assign default values when
de-serializing a message where the element defined with a default value
is missing.

This has implications both when a developer sends a message with a
payload serialized from a generated type and when a message is received
/ de-serialized.  On the way out, the developer needs to distinguish
between a NULL value, a "left-unsaid" value, and an explicit "use the
default" value (since the message *has* to contain an empty element for
the default value to be injected).  This outbound issue overlaps a great
deal with ISSUE-7.  On the inbound case, some type serialization tools
inject the default value even when the element is absent from the
message.  This is probably a side-effect of having the default value
assigned in the class constructor.  

Example:  Given this schema and message content:

<xs:element name="NewAccount">
      <xs:complexType>
            <xs:sequence>
                  <xs:element name="Name" type="xs:string"/>
                  <xs:element name="CreditLimit" default="1000"
minOccurs="0" type="xs:decimal" />
            </xs:sequence>
      </xs:complexType>
</xs:element>

<t:NewAccount xmlns:t="urn:epic:schematest1">
      <t:Name>MegaCorp</t:Name>
</t:NewAccount>

A PSVI emitted from a schema validation tool will correctly NOT contain
a "CreditLimit" node because that element MUST appear in the received
XML document with empty content.  But an instance X of the
type-generated class NewAccount will have member values assigned like
this: X.Name="MegaCorp", X.CreditLimit=1000.00, which is incorrect.

Solution: Type de-serializers should not apply default values unless the
XML payload has the relevant element present with empty content.
Generated types MAY apply default values to new class instance members.
Generated types SHOULD provide an explicit mechanism for developers to
serialize a class member as an empty element with the intention that the
receiver will inject default values in a PSVI. 

Erik Johnson
Epicor Software Corp.

* I am awash in .NET projects at the moment, so it's the first place I
go to look for issues!
"""

http://lists.w3.org/Archives/Public/public-xsd-databinding/2006Jan/0032.html

Received on Tuesday, 24 January 2006 23:28:20 UTC