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

Re: Question on use="required"

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 14 Aug 2002 15:44:13 +0100
Message-ID: <10177289829.20020814154413@jenitennison.com>
To: Stefan Wachter <Stefan.Wachter@gmx.de>
CC: xmlschema-dev@w3.org

Hi Stefan,

> I agree with your answer that in the instance document there must
> appear a value for an attribute whose use is required. But I think
> it would be good to allow value constraints for such attributes in
> the schema for two reasons:
>
> 1. If I want to express that an attribute must be present and have a
> certain value.

Yes, as I said you *are* allowed to have an attribute that is both
required and has a fixed value, which is very useful.

> 2. There is a great schema which I import and which contains value
> constraints for various declarations. Some people (like me) do not
> like default values and want that an instance author must specify
> all values. Therefore I would restrict the imported declarations by
> adding the use="required" attribute. These declarations would now
> have value constraints and the use="required" attribute.

That's fine. When you restrict a complex type, the attribute uses on
the type consist of those that you've specified explicitly during your
restriction plus some inherited from the base type (but you don't
inherit those that have the same name as those that you've specified
explicitly).

So, if you specify an attribute use in a derivation then that
attribute use is entirely as specified by you. You don't inherit value
constraints (fixed or default) from the attribute in the base type. So
the resulting attribute doesn't have a default value unless you
explicitly specify one. (And in some circumstances, namely if the
attribute in the base type has a fixed value, you *must* specify one
-- see Clause 2 of
http://www.w3.org/TR/xmlschema-1/#derivation-ok-restriction.)

> PS: So there is an error in the Microsoft testcase
> attribute/attP009.xsd. Theres is the complexType
>
>         <xsd:complexType name="attRef">
>                 <xsd:attribute name="att" use="required" fixed="37"/>
>         </xsd:complexType>
>
> which is valid. But in the accompanying instance document
> attP009.xml there is no value for the attribute.

I haven't looked at it, but if it's as you describe then yes, that's
an error.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Wednesday, 14 August 2002 10:44:14 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:34 GMT