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

Re: Sometimes an empty value means "use the default value" and sometimes it doesn't ... right?

From: Michael Kay <mike@saxonica.com>
Date: Thu, 23 Aug 2012 21:33:07 +0100
Message-ID: <50369383.4070303@saxonica.com>
To: xmlschema-dev@w3.org
The schema spec says that the default value for an element is used when 
the element is empty (has no text or element children). It doesn't say 
that the default is used when the element would otherwise be invalid.

Michael Kay
Saxonica



On 23/08/2012 20:04, Costello, Roger L. wrote:
> Hi Folks,
>
> Here is a schema that has an Altitude element with a default value of 100, and a Title element with a default value of "Hello World"
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>      
>      <xs:element name="Tests">
>          <xs:complexType>
>              <xs:sequence>
>                  <xs:element name="Test1">
>                      <xs:complexType>
>                          <xs:sequence>
>                              <xs:element name="Altitude" type="xs:integer" default="100" />
>                          </xs:sequence>
>                      </xs:complexType>
>                  </xs:element>
>                  <xs:element name="Test2">
>                      <xs:complexType>
>                          <xs:sequence>
>                              <xs:element name="Title" type="xs:string" default="Hello World" />
>                          </xs:sequence>
>                      </xs:complexType>
>                  </xs:element>
>              </xs:sequence>
>          </xs:complexType>
>      </xs:element>
>
> </xs:schema>
>
> Here is an instance document that has an empty value for both Altitude and Title
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Tests>
>      <Test1>
>          <Altitude></Altitude>
>      </Test1>
>      <Test2>
>          <Title></Title>
>      </Test2>
> </Tests>
>
> Since the empty value is not a valid integer, the Altitude element must assume the default value, 100.
>
> Since the empty value is a valid string, the Title element does not assume the default value; its value is the empty string.
>
> Thus sometimes an empty value means "use the default value" and sometimes it doesn't.  Right?
>
> /Roger
>
>
Received on Thursday, 23 August 2012 20:33:22 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 23 August 2012 20:33:23 GMT