问题
Which HTML5 markup should we use for postal addresses? And which vocabulary could we use for enabling machine-readability?
As an example, the address of W3C’s main office:
W3C/MIT
32 Vassar Street
Room 32-G515
Cambridge, MA 02139 USA
回答1:
The address element must only be used if this postal address represents the contact information for "its nearest article
or body
element ancestor", which, of course, is not the case for all addresses. But if address
is used or not, it doesn’t affect the following.
The whole address should be enclosed in a p element, because "an address is also a paragraph".
As addresses should not be translated, the translate attribute should be set to no
.
Each line (except the last one) should be followed by a br element, because the line breaks are meaningful (or "part of the content", as the HTML5 spec calls it) in addresses.
Each address part (name, street, city, etc.) can be enclosed in a span element. This is not required, but allows the use of semantic annotations.
Abbreviated address parts can be expanded with the abbr element, which can be useful for users not familiar with the address format (e.g., "What means MA?").
So up to this point, we have:
<p translate="no">
W3C/MIT<br>
32 Vassar Street<br>
Room 32-G515<br>
Cambridge, <abbr title="Massachusetts">MA</abbr> 02139 USA
</p>
Vocabularies
Schema.org’s PostalAddress type can be used for all address parts except for the room.
The vCard Ontology (which maps vCard to RDF) defines an Address class. There doesn’t seem to be a way to specify the room.
Another Address class is defined in the ISA Programme Location Core Vocabulary. The room can be specified with the locatorName property.
Microformats has h-card (with its p-adr
) and h-adr. The room can be specified with p-extended-address
.
Using the schema.org vocabulary with RDFa (Lite) as an example:
<p translate="no" typeof="schema:PostalAddress">
<span property="schema:name">W3C/MIT</span><br>
<span property="schema:streetAddress">32 Vassar Street</span><br>
Room 32-G515<br>
<span property="schema:addressLocality">Cambridge</span>, <abbr title="Massachusetts" property="schema:addressRegion">MA</abbr> <span property="schema:postalCode">02139</span> <abbr property="schema:addressCountry">USA</abbr>
</p>
来源:https://stackoverflow.com/questions/26188003/markup-for-postal-addresses