In the following example, Microdata’s itemref
attribute is used to add the email
property to the Person
item (both from a fictive Microdata vocabulary).
<body>
<div itemscope itemtype="http://example.org/Person" itemref="orphan">
<span itemprop="name">Alice</span>
</div>
<div id="orphan" itemprop="email">
alice@example.com
</div>
</body>
Is this valid Microdata?
If I understand the "Associating names with items" algorithm correctly, the "itemref
ed" properties are not moved but copied, which leaves this "orphan" itemprop
without an item parent.
There are three valid cases for itemprop
values. The following one seems to come closest:
If the item is not a typed item: a string that contains no "." (U+002E) characters and no ":" (U+003A) characters.
(Which would mean that the orphaned property is not a "defined property name", i.e., it doesn’t belong to the fictive vocabulary anymore (only the "copied" property does).)
But: there is no "item" involved, as there is no itemscope
.
So you can’t specify itemprop
without a parent itemscope
at all? Doesn‘t seem so:
Every HTML element may have an
itemprop
attribute specified […]
What am I’m missing in the Microdata specification?
Does an itemprop
without an itemscope
parent create an item?
The spec requirement is just that the itemprop is used in at least one item. There's no suggestion that I can see that being referenced by an itemref does not constitute a usage, nor that the itemprop is copied, and that it is the copy which is used not the original. So I think the spec requirements are fulfilled, and the microdata is valid.
Moreover, consider the intent of the spec. The underlying idea is that an itemprop that is not used by any item is pointless - a waste of typing - an therefore must be an authoring mistake. That is sufficient for mark-up to be considered invalid. Since that is not the case here, there is no justification for making such a construct invalid.
- Is this valid Microdata?
- Yes it is!
- Does an itemprop without an itemscope parent create an item?
- No it doesn't!
An item is created by the itemscope attribute. With or with out properties, it is an item ones you declared it as an item. An itemprop declares the property of an item, it will never create it. It is still valid html to have the itemprop attribute declared on "orphans" sense there is no dependencies in html on attributes like does on elements.
http://www.w3.org/TR/2011/WD-microdata-20110405/#the-basic-syntax 9:th example describes the topic bit.
I work with these type of extractions a lot. The way I designed the software is to look for the root of every item, that's where the scope is declared. I then extend the scope if a reference is declared. I never look for properties outside the scope sense it's irrelevant.
来源:https://stackoverflow.com/questions/21369695/is-itemprop-without-parent-itemscope-valid-does-it-create-an-item