benjaminjosephw
benjaminjosephw

Reputation: 4417

How to markup a document with RDFa when data is across multiple elements

I have the following HTML structure:

<address>
  <div>Address Line One</div>
  <div>Address Line Two</div>
  <div>Address Line Three</div>
  <div>Post Code</div>
</address>

Since the data I have is does not consistently have regions or localities, I cannot reliably use the properties addressRegion and addressLocality as defined at schema.org. Instead, I think I should be using the streetAddress property for everything except the post code.

My question is whether this is valid RDFa markup?:

<address property="address" typeof="PostalAddress">
  <div property="streetAddress">Address Line One</div>
  <div property="streetAddress">Address Line Two</div>
  <div property="streetAddress">Address Line Three</div>
  <div property="postalCode">Post Code</div>
</address>

If not, is there another way to do this without changing the structure of the HTML?

Upvotes: 1

Views: 173

Answers (2)

scor
scor

Reputation: 940

You can wrap your series of div elements with a higher level div:

<address property="address" typeof="PostalAddress">
  <div property="streetAddress">
    <div>Address Line One</div>
    <div>Address Line Two</div>
    <div>Address Line Three</div>
  </div>
  <div property="postalCode">Post Code</div>
</address>

Upvotes: 1

unor
unor

Reputation: 96607

Your markup is syntactically valid, but it’s probably not conveying what you mean.

You are adding three street addresses (!) to the PostalAddress node, but

  • consumers have no reason to assume that these are three parts of actually one street address, and

  • RDFa doesn’t rely on the relative order of these triples anyway (unless you are using lists), so when a consumer queries your data, these three streetAddress values could come up in any order.

So without changing something (I’m not sure what exactly you mean with "structure") in your HTML, you can’t fix this.

scor suggests to add a parent div, which is a good and easy solution.

There are many other ways how to add this triple (for example, adding a meta element giving the full street address and removing the properties from the div elements), but unless you have some special constraints about what you can/cannot change in your HTML, go with the div.


Side note about your markup:

Based on my recommendation for postal address markup, I’d use br elements for separating the street address lines, with optional span elements if a grouping, like in your case, is needed:

<address>
  <p property="schema:address" typeof="schema:PostalAddress">
    <span property="schema:streetAddress">
      Address Line One<br>
      Address Line Two<br>
      Address Line Three<br>
    </span>
    <span property="schema:postalCode">
      Post Code
    </span>
  </p>
</address>

That said, I’d question your use of Schema.org’s streetAddress property. Regions or localities should not be included, because, well, they are not part of the "street address". I’d only mark up the actual street address, even if that would mean in your case that the region and the locality don’t get included in the graph.

Upvotes: 1

Related Questions