Re: data-* attributes (and regrets)

On 12 December 2014 at 11:07, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 12/12/14, 11:56 AM, Erik Dahlström wrote:
>
>> Blink has been shipping with dataset on Element for some time, with no
>> reported issues related to this AFAICT.
>>
>
> Indeed.  I don't think there's a web compat issue here; the only issue is
> whether we want to just dictate that all XML vocabularies going forward
> have these global attributes that they're not allowed to use for anything
> internal to the vocabulary.


>From an XML perspective, the really useful method would be
`.getAttributesByNS()`, to allow you to use whatever data namespaces you
like and get a dataset-type object of all the values at once.

But HTML is leading the charge on this one, and HTML doesn't like
namespaces.  Enabling special access to `data-` attributes through
`dataset` doesn't prevent them from being used within a particular XML
schema, but it does mean that authors using that schema can't effectively
use dataset for their own purposes.

A contrasting approach is used for the `aria-` attributes, which defines
standard attributes, but then allows ARIA-implementing languages to decide
whether they want to adopt those attributes into their default namespace or
require a specific aria namespace declaration.
http://www.w3.org/TR/wai-aria/host_languages

However, the difference is that ARIA doesn't currently have a DOM API
(although it often would be useful if it did!), so there is no issue from a
DOM perspective of whether it would be convenient to define methods on
generic Element versus namespace-specific element models.

What do people think of the feasibility of this approach:

- Separate out the definition of `data-` attributes and the `dataset`
property into its own specification, and give it a namespace;

- Indicate that *any* XML document can include data attributes by using the
dataset namespace;

- Allow specific languages, such as XHTML and SVG, to adopt data-
attributes into the default namespace;

- Add the dataset property to the Element interface, but require it to
check if the dataset namespace is defined in the document; if it is, only
grab attributes from that namespace, otherwise grab attributes from the
default namespace.

There are still complexities:

- I'm not sure how the "any attribute starting with data- is valid" rule
could be implemented in XML validation models.

- The capitalization rules for transforming between hyphenated, all
lowercase attribute names and camelCase object property names are
unnecessarily complicated in XML, with its case sensitive attributes.  To
ensure a 1 to 1 conversion that can always be correctly inverted, the rule
would have to be "any attribute starting with data- and not containing any
uppercase letters is valid".

Just ideas.  At the very least, I would love to see .dataset universally
implemented on SVGElement.

Amelia BR

Received on Saturday, 13 December 2014 18:45:05 UTC