[whatwg] adding microdata to basic links

Stéphane Corlosquet scorlosquet at gmail.com
Thu Dec 8 18:51:33 PST 2011


Hi Ian,

On Thu, Dec 8, 2011 at 5:11 PM, Ian Hickson <ian at hixie.ch> wrote:

> On Wed, 24 Aug 2011, Stéphane Corlosquet wrote:
> >
> > Starting from a basic markup like this:
> > [[[
> > This book has been authored by <a href="http://smith.org/john">John
> > Smith</a>.
> > ]]]
> >
> > I would like to markup both the textContent of the link ("John Smith")
> and
> > the url from the href attribute.
> >
> > In RDFa this is done by adding a couple of attributes to the a element.
> It
> > would read like this:
> > [[[
> > This book has been authored by <a property="name" rel="url" href="
> > http://smith.org/john">John Smith</a>.
> > ]]]
> >
> > Is there any way to do the same in microdata without adding a new HTML
> > element to the markup?
>
> On Wed, 24 Aug 2011, Tab Atkins Jr. wrote:
> >
> > No, Microdata purposely keeps its data model simple by expressing
> > property names through a single attribute.  Since having @itemprop on an
> > <a> always refers to the @href of the element, you must nest an
> > additional element, such as a <span>, into your markup to carry the
> > property that refers to the text content.
>
> Indeed.
>
> The reasoning is that it's hard to understand otherwise; e.g. it's not at
> all immediately obvious to me that this is wrong, though it is:
>
>   <a property="url" href="http://smith.org/john">John Smith</a>
>

I agree, and I have seen people doing that mistake (including myself!). The
RDFa WG received a lot of similar feedback, so it was decided to do
something about it. While the snippet above is wrong in RDFa 1.0, it is
correct in RDFa 1.1 (@property will pick up @href if there is no @rel). So
you can write RDFa without using @rel in the same fashion as microdata.
That's a good example of microdata design feeding into other standards.

Steph.


>
> ...and while an experienced author would know that "rel" is to "href" as
> "property" is to the contents, an inexperienced one might still make
> mistakes such as:
>
>   <a property="url" href="http://smith.org/john"
>      rel="name">John Smith</a>
>
> In microdata, <a> always gives the URL, which simplifies it a bit, at the
> cost of making this example more verbose.
>
>
> On Wed, 24 Aug 2011, Tantek Ã~Gelik wrote:
> >
> > This does seem to be a (fairly common) case where microdata requires
> > additional markup (another element) whereas both microformats (e.g.
> > hCard) and [RDFa] (through the perhaps questionable overloading of
> > 'rel') do not.
>
> Yeah. Microformats 2 has an interesting compromise solution where
> Hungarian notation is used to denote the type of the property, and that
> type is used to determine how it is read. The cost of that of course is
> the slightly more verbose markup in all property names.
>
>
> On Wed, 24 Aug 2011, Stéphane Corlosquet wrote [edited for simplicity]:
> >
> > [[[
> > This book has been authored by
> >     <span vocab="http://schema.org/" typeof="Person">
> >         <a property="name" rel="url" href="http://smith.org/john">John
> > Smith</a>
> >     </span>
> > ]]]
>
> On Wed, 24 Aug 2011, Edward O'Connor wrote [edited for brevity]:
> >
> > This could be represented in Microdata without an extra element:
>
> Well, microdata needs to use an element that is undecorated in the
> original, namely the <p> that I removed in the quote above:
>
> > <p itemscope itemtype="http://schema.org/Person">
> >     This book has been authored by
> >         <span itemprop="name">
> >             <a itemprop="url" href="http://smith.org/john">John
> > Smith</a>
> >         </span>
> > </p>
>
> The microformats for this particular case is shorter still.
>
>
> I haven't changed microdata for this; the current design is an intentional
> trade-off between verbosity and predictability.
>
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list