ISSUE-14

xs:default handling by generated types

State:
CLOSED
Product:
Advanced
Raised by:
Everyone
Opened on:
2006-01-24
Description:
"""
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
Related emails:
  1. ISSUE-14: xs:default handling by generated types (from dean+cgi@w3.org on 2006-01-24)
  2. Agenda: XML Schema Patterns for Databinding Telcon 31 January 2006 (from paul.downey@bt.com on 2006-01-30)
  3. Agenda: XML Schema Patterns for Databinding Telcon 7 February 2006 (from paul.downey@bt.com on 2006-02-06)
  4. Minutes from XML Schema Patterns for Databinding call 7 February 2006 (from paul.downey@bt.com on 2006-02-08)
  5. Agenda: XML Schema Patterns for Databinding F2F 27-28 February 2006 (from paul.downey@bt.com on 2006-02-22)
  6. Revised Agenda: XML Schema Patterns for Databinding F2F 27-28 February 2006 (from paul.downey@bt.com on 2006-02-27)
  7. Minutes from XML Schema Patterns for Databinding F2F 27-28 Feb 2006 (from paul.downey@bt.com on 2006-03-12)
  8. ISSUE-38: xs:any processContents value of \\'skip\\' (from dean+cgi@w3.org on 2006-04-25)
  9. Re: ISSUE-38: xs:any processContents value of \\'skip\\' (from Paul.V.Biron@kp.org on 2006-04-26)
  10. Re: ISSUE-38: xs:any processContents value of \\'skip\\' (from petexmldev@tech-know-ware.com on 2006-04-26)
  11. RE: ISSUE-38: xs:any processContents value of \\'skip\\' (from paul.downey@bt.com on 2006-04-28)
  12. RE: ISSUE-14: xs:default handling by generated types (from paul.downey@bt.com on 2006-05-04)
  13. ISSUE-46: fixed value attributes (from dean+cgi@w3.org on 2006-05-05)
  14. Minutes from XML Schema Patterns for Databinding F2F 22-23 May 2006 (from paul.downey@bt.com on 2006-06-02)
  15. Minutes: XML Schema Patterns for Databinding F2F 31st July - 1st August 2006 (from paul.downey@bt.com on 2006-08-01)
  16. Minutes: XML Schema Patterns for Databinding F2F 5th-6th October 2006 (from paul.downey@bt.com on 2006-10-07)

Related notes:

2006-08-01: moved to advanced at August 2006 F2F

2006-10-05: Accepted as an Advanced pattern, needs example