Re: Help with Default please

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