W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

Re: Default values

From: Jeni Tennison <jeni@jenitennison.com>
Date: Sat, 9 Feb 2002 11:20:40 +0000
Message-ID: <261038006574.20020209112040@jenitennison.com>
To: SysGrad <SysGrad@library.msstate.edu>
CC: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Hi Mahesh,

> I know that we can have one dafault specified for any element in the
> XML file using DTD or XML-schema. But can we specify a set of
> default values to one element.So that when I open a an XML file in
> browser and that element is specified empty in the XML file. But
> there are set of default values specifed in DTD or XML -schemas,
> then those set of values should be displayed...
> My Question is can we give a set of default values?
I'm not sure what you mean by a set of default values. Perhaps you
mean that you want the element to take a list by default, so for
example, you want the foo element to take a list of the integers 1, 2
and 3 by default, such that:

  <foo />

is interpreted the same as:

  <foo>1 2 3</foo>

by a schema-aware processor?

If so, you just use the default attribute in the same way as you do
normally. The type of the element must be a list type, for example:

<xs:element name="foo" default="1 2 3">
    <xs:list itemType="xs:integer" />

I suppose the other possibility is that you want to have an XML
structure as the default value, for example so that <foo /> it
interpreted the same as:


I'm afraid that there isn't a way of doing that in XML Schema. I'd
recommend you approach that problem by having an XSLT transformation
that adds such default values prior to validation of the XML instance.

If neither of these are what you're talking about, please give a
simple example that illustrates what you want to do.



Jeni Tennison
Received on Saturday, 9 February 2002 06:20:42 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:59 UTC