users@jaxb.java.net

Re: JAXB 2.0 default values

From: Joe Fialli <Joseph.Fialli_at_Sun.COM>
Date: Wed, 07 Sep 2005 14:38:36 -0400
Dmitri Colebatch wrote:
Hi Joe,

[snip]

  
If a child element is missing,
nothing is done by the unmarshal process. 
    

I don't understand the logic behind this.  Are you saying that if I have:

<foo>
  <bar />
</foo>

where in the schema bar has a default value of "x" then
foo.getBar().equals("x")?  Yet if I have

<foo />

foo.getBar() is null?  
  
Yes.  That is how it is defined in W3C schema.

Non-normative description of element defaulting is in 4th PH in following URL.
URL: http://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints

Also, the following relevant rows summarize extracted from http://www.w3.org/TR/xmlschema-0/#cardinalityTable
Elements
(minOccurs, maxOccurs)
fixed, default
Attributes
use, fixed, default
Notes
(0, 1) 37, - n/a element may appear once, if it does not appear it is not provided; if it does appear and it is empty, its value is 37; if it does appear and it is not empty, its value must be 37
(0, 1) -, 37 n/a element may appear once; if it does not appear it is not provided; if it does appear and it is empty, its value is 37; otherwise its value is that given

Normative description from W3C XML Schema spec:
http://www.w3.org/TR/xmlschema-1/#sic-eltDefault


Without being an expert on default/absent/empty/nil values, I would
have thought that the use case for default values was to save the need
to put them in (an xml document) at all.

Could you please point me to something explaining why it is done this way?
  

No rationale is provided for this in XML Schema specification on why it is done this way.

-Joe
cheers
dim

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@jaxb.dev.java.net
For additional commands, e-mail: users-help@jaxb.dev.java.net