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

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 UTC