W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2012

Re: XML Schema quiz on default values

From: Costello, Roger L. <costello@mitre.org>
Date: Fri, 24 Aug 2012 11:48:03 +0000
To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-ID: <B5FEE00B53CF054AA8439027E8FE17751E62FDFC@IMCMBX04.MITRE.ORG>
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
Received on Friday, 24 August 2012 11:48:31 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 24 August 2012 11:48:31 GMT