[whatwg] Embedding custom hierarchical data

Hay (Husky) huskyr at gmail.com
Tue Mar 15 13:06:55 PDT 2011

Hi everyone,
what would be the 'preferred' way to embed custom hierarchical data in
a HTML document?

Consider, for example, a list that contains custom data that needs to
be displayed using Javascript. In most cases, the data-* attributes
are a nice way to embed non-visual data to be read out later, but that
doesn't work for hierarchical structures. There are a few possible

1) Microdata. This could work, but only if the data should be
displayed as well. If the data should be processed (and for example,
be shown in another part of the page) this doesn't work really well.
You could the hide the parent element with CSS, but that's pretty

2) data-* attributes with JSON data. Would work, but pretty ugly and
not very expressive and readable.

3) 'Data blocks' in a <script> element, as described in the spec. You
can, for example, use a <script> element with an 'application/xml' or
'application/json' type, which will not be processed by a browser, and
use Javascript to do the parsing.

Data blocks seem to be the current most usable solution, but i get the
feeling that it's not quite expressive enough. <script> tags should
contain scripts, and XML and JSON are not scripting languages.
Semantically, 'xml islands' as used in older versions of IE seem like
an elegant solution but are not supported in other browsers.

Something like a <data> tag, with a required 'type' attribute that can
contain a mime type that could indicate to browsers what type of
content follows might be an interesting solution, but i'm not sure
what the implications might be.It would be cool if you do a <data
type="application/json"> and get an automatic Javascript object when
getting the element with document.getElementById.

-- Hay Kranen

More information about the whatwg mailing list