[whatwg] Microdata - Handling the case where a string is upgraded to an object

On Mon, Jul 18, 2011 at 4:20 AM, Philip J?genstedt <philipj at opera.com> wrote:
> There is no items IDL attribute, do you mean getItems() or .itemValue
> perhaps?

Yes, sorry.


> I take it the problem is with code like this:
>
> <div itemscope itemtype="person"><span itemprop="name">Foo
> Barsson</span></div>
> <script>
> var p = document.getItems("person")[0];
> alert(p.properties.namedItem("name")[0].itemValue);
> </script>
>
> If the HTML changes to
>
> <div itemscope itemtype="person"><span itemprop="name" itemscope><span
> itemprop="givenName">Foo</span> <span
> itemprop="familyName">Barsson</span></span></div>
>
> then the script would be alerting "[object HTMLElement]" instead of "Foo
> Barsson".
>
> I'm not sure why this would be a problem. If someone changes the page, then
> can't they adjust the script to match?

That only works if the page is using its own Microdata, not if someone
else is consuming the Microdata.

> Is it extensions and libraries that
> you're worried about?

Yeah.  I suspect this kind of API change is relatively common, and
it's the sort of thing that would *always* be painful.

> As for the solution, are you suggesting that .itemValue return a special
> object which is like HTMLElement in all regards except for how it
> toString()s?

Yes.

~TJ

Received on Monday, 18 July 2011 13:01:37 UTC