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

Re: Help with Default please

From: Eddie Robertsson <erobertsson@allette.com.au>
Date: Mon, 15 Jul 2002 10:35:19 +1000
Message-ID: <3D3218C7.1030601@allette.com.au>
To: Gary Cramblitt <garycramblitt@comcast.net>
CC: xmlschema-dev@w3.org

Hi Gary,

Gary Cramblitt wrote:

>I want to define an element in such a way that the default is applied 
>whether the instance document specifies the element or not.
>
Unfortunately you can't do this with W3C XML Schema. The best you can do 
is to say that if the element exist and has empty content then it should 
default to a value specified in the schema.

>If an instance document does not specify element foo, then the 
>post-validation DOM will contain the element with value "bar".  
>
You can't do this.

>If the instance document specifies the element, but leaves the 
>contents blank, i.e.,
>
>  <foo></foo>
>
>then the post-validation DOM will also contain the element with 
>value "bar".  If user specifies a value, 
>
You can do this by using the default attribute on the element declaration.

>  <foo>yea</foo>
>
>that value appears in the post-validation DOM.
>
>I think what I want for my XML-Schema is
>
><xs:element name="foo" minOccurs="0" maxOccurs="1" 
>default="bar"/>
>
>Is this correct?
>
Yes, but it won't insert the element "foo" if it's missing from the 
instance document.

Cheers,
/Eddie

>
>--
>Gary Cramblitt
>garycramblitt@comcast.net
>
>
>  
>
Received on Sunday, 14 July 2002 20:21:25 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:57 UTC