OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

relax-ng message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]

Subject: Re: Attribute defaults

> RELAX NG does not allow you specify defaults for attributes (see section A
> of the tutorial
> http://www.oasis-open.org/committees/relax-ng/tutorial.html#c41b1c17).
> anyone else see this as a tripwire? Example: when you try to rewrite
> something as RELAX NG, such as an XML Schema attribute declaration with
> default="string", what do you do?

Use an annotation:

  <attribute name="foo" x:defaultValue="true">
    <data type="boolean"/>

Default attribute values in XML serve two purposes:

a) Documentation: they tell a human that if the attribute is not specified,
the document will be interpreted as if the attribute has been specified with
a particular value

b) Processing: an application doesn't have to handle the case when the
attribute is missing

I think (b) is an illusion.  Robust code cannot rely on the attribute being
present.  The DTD may not have been specified or perhaps the parser didn't
read the DTD (as XML 1.0 permits). In any case, it is certainly possible
that the attribute will be missing when the application gets the document; a
conscientious developer will try to handle and recover from that. It would
also be hard to add this to RELAX NG: it would require complex restrictions
on determinism.

(a) is useful, but I think it is more appropriately served by an annotation.
We could even have a standard annotation namespace with some useful
annotations (like a standard name for human-readable documentation)
including attribute default values.

At the moment RELAX NG processing is purely validation: it involves
answering the question is this document valid with respect to the schema,
and no more. Introducing default values would change this: RELAX NG would be
also providing information about how the document should be processed.  The
XML default attribute mechanism allows you to say: if a particular element
does not have a particular attribute, then it should be processed as it had
that attribute with a particular fixed value.  Why is that the only thing
you should be able to say about how the document is processed?  What if I
want to say that if a particular attribute is not present, it should be
inherited or it should default to the value of some other attribute?  What
if I want to say that if some child element is not present, a child element
with a particular value should be added by default?


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]

Powered by eList eXpress LLC