If attribute default present, 'use' must be optional

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

If attribute default present, 'use' must be optional

Pete Cordell-5
Just curious...

why in XSD section 3.2.3 Constraints on XML Representations of Attribute
Declarations, Schema Representation Constraint: Attribute Declaration
Representation OK (http://www.w3.org/TR/xmlschema11-1/#sec-src-attdecl) does
it say:

    2 If default and use are both present, use must have the ·actual value·
optional

Why can't a schema designer choose to have a mandatory attribute with a
default value?

Thanks,

Pete Cordell
Codalogic Ltd
Interface XML to C++ the easy way using C++ XML
data binding to convert XSD schemas to C++ classes.
Visit http://codalogic.com/lmx/ or http://www.xml2cpp.com
for more info


Reply | Threaded
Open this post in threaded view
|

Re: If attribute default present, 'use' must be optional

G. Ken Holman
At 2012-03-23 10:53 +0000, Pete Cordell wrote:

>Just curious...
>
>why in XSD section 3.2.3 Constraints on XML
>Representations of Attribute Declarations,
>Schema Representation Constraint: Attribute
>Declaration Representation OK
>(http://www.w3.org/TR/xmlschema11-1/#sec-src-attdecl) does it say:
>
>    2 If default and use are both present, use
> must have the ·actual value· optional
>
>Why can't a schema designer choose to have a
>mandatory attribute with a default value?

What would a default value mean if it never,
ever, gets used because the instance *always* overrides it?

Would that not be misleading to someone?  Either
the schema writer or the user or both?

. . . . . . . . Ken


--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/uoui9h
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/x/
G. Ken Holman                   mailto:[hidden email]
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


Reply | Threaded
Open this post in threaded view
|

Re: If attribute default present, 'use' must be optional

Pete Cordell-5
Original Message From: "G. Ken Holman"

At 2012-03-23 10:53 +0000, Pete Cordell wrote:

> >Just curious...
> >
> >why in XSD section 3.2.3 Constraints on XML Representations of Attribute
> >Declarations, Schema Representation Constraint: Attribute Declaration
> >Representation OK (http://www.w3.org/TR/xmlschema11-1/#sec-src-attdecl)
> >does it say:
> >
> >    2 If default and use are both present, use must have the ·actual
> > value· optional
> >
> >Why can't a schema designer choose to have a mandatory attribute with a
> >default value?
>
> What would a default value mean if it never, ever, gets used because the
> instance *always* overrides it?
>
> Would that not be misleading to someone?  Either the schema writer or the
> user or both?


I think a mandatory attribute with a default is telling an XML creator that
if they don't have a specific value for this field then they should set it
to the default value.  This can help the consumer of the XML because they
don't need to be so schema aware and know about default values.  Equally,
the human reading the XML doesn't need to be so aware of the schema either.
It can also act as a very useful form of documentation to the human schema
users.

It seems the current rule is too SQL schema (or similar) derived.  And IMO
it also attempts to dictate 'common sense', but because the authors are not
omnipotent, may not be common sense it all situations that it could be
useful.  Hence it decreases the usefulness of XSD while increasing its
complexity.

Pete Cordell
Codalogic Ltd
Interface XML to C++ the easy way using C++ XML
data binding to convert XSD schemas to C++ classes.
Visit http://codalogic.com/lmx/ or http://www.xml2cpp.com
for more info


Reply | Threaded
Open this post in threaded view
|

Re: If attribute default present, 'use' must be optional

Michael Kay

>
> I think a mandatory attribute with a default is telling an XML creator
> that if they don't have a specific value for this field then they
> should set it to the default value.
Except that the XSD spec doesn't have any way of saying that that's what
it's saying, because it doesn't define semantics for this use case; the
only semantics defined for the schema is its effect on validation / PSVI
creation. That means that if XSD allowed this, it would have to say
"this is allowed but has no recognized meaning".

Now there are in fact plenty of cases where XSD does allow things that
have no recognized meaning, and there are two schools of thought about
whether this is good or bad. The debate is generally conducted under the
name "paternalism": a paternalistic design stops you doing something
which is apparently pointless but not actively harmful (like creating a
choice with no members). Another example occurs with facet-based
restriction, where we prevent you from defining a minInclusive that is
less than the minInclusive of your base type.

It's hard to get this right consistently. In many cases I think the
right approach when users do something pointless is a warning (which is
of course outside the scope of the spec). But should we, for example,
allow you to specify minInclusive for an xs:QName, given that it will
have no effect? I think not. And specifying a default for a mandatory
attribute seems to me to fall into the same category.

Michael Kay
Saxonica

Reply | Threaded
Open this post in threaded view
|

Re: If attribute default present, 'use' must be optional

Pete Cordell-5
Original Message From: "Michael Kay"

>> I think a mandatory attribute with a default is telling an XML creator
>> that if they don't have a specific value for this field then they should
>> set it to the default value.
> Except that the XSD spec doesn't have any way of saying that that's what
> it's saying, because it doesn't define semantics for this use case; the
> only semantics defined for the schema is its effect on validation / PSVI
> creation. That means that if XSD allowed this, it would have to say "this
> is allowed but has no recognized meaning".

Do you mean that XSD only specifies semantics for parsing XML documents, not
actually generating them?

It may be the OO programming background of the customers I work with, but
most of them seem to expect (or want) 'default' to mean, "If I don't
explicitly set the value, then use the default value when generating the
XML."

Potentially the end-to-end effect of a optional attribute filled with the
default value at the receiving end is the same as a mandatory attribute
filled with the default value at the originating end, but it can aid
debugging and clarity if the default value is made explicit in the
transferred XML.

> ...
>
> It's hard to get this right consistently. In many cases I think the right
> approach when users do something pointless is a warning (which is of
> course outside the scope of the spec). But should we, for example, allow
> you to specify minInclusive for an xs:QName, given that it will have no
> effect? I think not. And specifying a default for a mandatory attribute
> seems to me to fall into the same category.

I agree a minInclusive for an xs:QName is nonsensical.  However, I think
setting a default for a mandatory value is at worst redundant, and can be
useful in a number of situations.

Pete Cordell
Codalogic Ltd
Interface XML to C++ the easy way using C++ XML
data binding to convert XSD schemas to C++ classes.
Visit http://codalogic.com/lmx/ or http://www.xml2cpp.com
for more info


Reply | Threaded
Open this post in threaded view
|

Re: If attribute default present, 'use' must be optional

Michael Kay

> Do you mean that XSD only specifies semantics for parsing XML
> documents, not
> actually generating them?
>
>
Sure. Schemas are used for all kinds of things like data binding and
syntax-directed editing that aren't defined in the XSD spec; the only
application of an XML schema that's defined in the spec is instance
"validation" (which of course includes annotation/augmentation of the
instance as well as verification).

Michael Kay
Saxonica

Reply | Threaded
Open this post in threaded view
|

Re: If attribute default present, 'use' must be optional

Pete Cordell-5
Original Message From: "Michael Kay" >

>> Do you mean that XSD only specifies semantics for parsing XML documents,
>> not
>> actually generating them?
>>
>>
> Sure. Schemas are used for all kinds of things like data binding and
> syntax-directed editing that aren't defined in the XSD spec; the only
> application of an XML schema that's defined in the spec is instance
> "validation" (which of course includes annotation/augmentation of the
> instance as well as verification).

Hum.  Can't help thinking that defaultness and cardinalitiness are fairly
orthogonal concepts.  Are pattern facets prevented if enumeration facets are
present?

I guess one persons paternalness is another persons meddlesomeness.

Pete Cordell
Codalogic Ltd
Interface XML to C++ the easy way using C++ XML
data binding to convert XSD schemas to C++ classes.
Visit http://codalogic.com/lmx/ or http://www.xml2cpp.com
for more info