Re: XML Schema quiz on default values

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 UTC