RE: XML Schema quiz on default values

Hello Daniel,

> this [default values] is definitely a dark corner of the specs.

I agree. 

Hopefully this discussion has shed some light on it.

/Roger

From: Daniel Dui [mailto:daniel.dui@gmail.com] 
Sent: Friday, August 24, 2012 8:33 AM
To: Costello, Roger L.
Cc: xmlschema-dev@w3.org
Subject: Re: XML Schema quiz on default values

Roger et al., thanks for the clarification.

I have used XML Schema for a long time and this is definitely a dark corner of the specs.

I always warn people about using default values and often recommend not using them. This non-obvious defaulting behavior looks to me like another reason why many schemas should avoid using default values.

-daniel

On 24 August 2012 12:48, Costello, Roger L. <costello@mitre.org> wrote:
Hello Daniel,

Suppose Title is declared like this:

    <xs:element name="Title" type="xs:string" default="Hello World" />
Note that a default value ("Hello World") is specified.

Now suppose we have this empty Title element in an instance document:

    <Title></Title>

What is the value of Title? Answer: it is the default value ("Hello World")

Conversely, suppose Title is declared like this:

    <xs:element name="Title" type="xs:string" />

Note that no default value is specified.

Now suppose we have this empty Title element in an instance document:

    <Title></Title>

What is the value of Title? Answer: it is a string of length zero (the empty string).

/Roger


So what should an instance document look like to have the default value
"Hello World"? Does this mean that the default value is of no practical use
for an xsd:string type?

-d


On 24 August 2012 10:05, Costello, Roger L. <costello@mitre.org> wrote:

> Thank you Michael and Pete for correcting my misunderstanding.
>
> Allow me to correct the answer to my quiz:
>
> I wrote this as the answer to my quiz:
>
>     >  Answer: the value of Title is the empty string, not the default
> value.
>     >  The reason is that the empty string is a valid value of the string
> data type.
>
> However, the correct answer is:
>
>  Answer: the value of Title is the default value ("Hello World"). The XML
> Schema specification explains why:
>
>     An element with a non-empty default value whose
>     simple type definition includes the empty string in
>     its lexical space will nonetheless never receive that
>     empty string value, because the default value will
>     override it.
>
> /Roger




-- 
____________________________________________________________
   Daniel Dui - daniel.dui@gmail.com - skype: danieldui

Received on Friday, 24 August 2012 13:36:29 UTC