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

XML Schema quiz on default values

From: Costello, Roger L. <costello@mitre.org>
Date: Thu, 23 Aug 2012 21:47:04 +0000
To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-ID: <B5FEE00B53CF054AA8439027E8FE17751E62FBC8@IMCMBX04.MITRE.ORG>
Hello Folks,

Recall that when you declare an element (or attribute) you can give it a default value.

For example, I give the Altitude element a default value of 100:

	<xs:element name="Altitude" type="xs:integer" default="100" />

In an instance document, if you wish for Altitude to have the default value, then you can simply create it as an empty element:


The value of Altitude is 100.

Let's take another example. Here I declare the Title element to be of type string and give it a default value, "Hello World":

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

Now in my instance document I create an empty Title element:


Quiz: What is the value of Title?

Scroll down to see the answer ...

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. If you want Title to have the default value then you must explicitly enter the default value:

	<Title>Hello World</Title>

Received on Thursday, 23 August 2012 21:47:32 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:20 UTC