Re: Default values

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:simpleType>
    <xs:list itemType="xs:integer" />
  </xs:simpleType>
</xs:element>

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:

  <foo><item>1</item><item>2</item><item>3</item></foo>

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.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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