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

Re: What is the type of an attribute with a default or fixed value? Is it always string?

From: C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com>
Date: Fri, 20 Jul 2012 19:58:25 -0600
Cc: "C. M. Sperberg-McQueen" <cmsmcq@blackmesatech.com>, "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-Id: <88E2F10F-B938-443D-BC42-A862BDEC5E79@blackmesatech.com>
To: "Costello, Roger L." <costello@mitre.org>

On Jul 20, 2012, at 5:19 AM, Costello, Roger L. wrote:

> Hi Folks,
> 
> In section 3.2.2 of the Structures specification it has a box showing this:
> 
>    XML Representation Summary: attribute Element Information Item
> 
>   <attribute
>         default = string
>         fixed = string
>         ...
> 
> I interpret that to mean the type of a default or fixed value is always string. Yes?

Not quite.

It means that the type of the attributes named 'default' and 'fixed' on
elements named xsd:attribute appearing in a valid schema document
is string.

The default or fixed value of the attributes being declared by those
xsd:attribute elements, however, is given by the property 
{value constraint}.{value} in the schema components constructed
from those xsd:attribute elements.

Sections 3.2.2.1 (http://www.w3.org/TR/xmlschema11-1/#dcl.att.global),
3.2.2.2 (http://www.w3.org/TR/xmlschema11-1/#dcl.att.local), and
3.2.2.3 (http://www.w3.org/TR/xmlschema11-1/#ref.att.local) describe
the component properties and how they are derived from the values
in the schema document.  in 3.2.2.3, for example, the description of 
{value constraint}.{value} says that its value is 

    the ·actual value· of the [attribute] (with respect to 
    {attribute declaration}.{type definition})

where "the attribute" refers to the default or fixed attribute in the source
declaration, and {attribute declaration}.{type definition} refers to the
type definition of the responsible attribute declaration.  

In less formal language:  the string in the schema document is mapped
to an 'actual value' in the value space of the attribute's declared type; that 
value is what is used as the default or fixed value of the attribute.

> 
> Suppose I declare this:
> 
>     <attribute name="pi" type="decimal" default="3.14" />
> 
> Suppose I use the default value in an XML instance document:
> 
>    pi = "3.14"

Actually, if this is part of your instance, you haven't used the
default value here, you've specified a value (which happens
to be the same as the default value).

> 
> Since the value is (presumably) a string type,

The rules I quote above specify that in the case you describe,
the default value of the 'pi' attribute will be the decimal value
mapped to by the string "3.14", and not the string "3.14" 
itself.  If pi were declared as being of type float, the default
value would be the float mapped to by "3.14".  And so on.

> it is nonsensical to perform arithmetic on it in, say, an XSLT program:
> 
>     @pi * diameter
> 
> And one should expect an error to be thrown. Yes?

That is precisely the consequence that the rules in the spec are
designed to circumvent.  And the kind of question about details like
how the type assignment is performed are precisely the kind of
question that the cumbersome and turgid "XML Mapping Rules"
are designed to answer.  Those rules are extremely pedantic and
verbose, and I expect many readers find them mind-numbling boring.
But anyone who wants to understand XSD at the level of detail 
implied by your question needs to learn how to read them.

I hope this helps.


-- 
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com 
* http://cmsmcq.com/mib                 
* http://balisage.net
****************************************************************
Received on Saturday, 21 July 2012 01:58:56 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 21 July 2012 01:58:56 GMT