Right way to set microdata for Q&A HTML

倖福魔咒の 提交于 2019-12-06 01:54:09

问题


Say one has a simple question and answer HTML and would like to add microdata, how should one proceed?

<h2>My Question</h2>
<p>My Answer</p>

I am aware of the schema.org example, but I don't find it very clear. It looks like overkill. I need a simple solution. Can I proceed this way?

<h2 itemscope itemtype="http://schema.org/Question">My Question</h2>
<p itemscope itemtype="http://schema.org/Answer">My Answer</p>

I just want to tell what the question is and what the answer is. Is this enough for search engines? Or should I have something more sophisticated like:

<div itemscope itemtype="http://schema.org/Question">
  <h2 itemprop="name">My Question</h2>
  <p itemscope itemtype="http://schema.org/Answer">My Answer</p>
</div>

Is using itemprop="name" the right way to tell what the question is? What is the difference between itemprop="name" and itemprop="text" in the schema.org example mentioned above?


回答1:


From your first example, Microdata parsers will only learn that there is a Question and an Answer item, without any further content. Microdata doesn’t specify that the content of HTML elements with itemscope attributes has to be considered, it only cares about property values.

Testing your example with some online Microdata parsers:

  • W3C’s Microdata to RDF Distiller extracts this RDF (in Turtle):

    <> md:item ( [ a schema:Question ] [ a schema:Answer ] );
        rdfa:usesVocabulary schema: .
    
  • The Structured Data Linter has almost the same output.

  • Yandex’s Structured data validator has similar output.

  • Google’s Structured Data Testing Tool doesn’t extract anything.


name vs. text

For this very question, the name would be "Right way to set microdata for Q&A HTML" and the text would be the question body ("Say one has a simple question …").

If the whole question consists only of such a single, short line, I’d use the text property instead of name (*). name could, principally, also be something like "Question 1", if you want/need it.

But you could also use both properties for a short question, i.e., itemprop="name text", but this is maybe not very elegant (but it can make sense especially if you know that some data consumer makes use of the name property).

* The example for Answer also uses text (and has no name).


You might also want to use Question’s suggestedAnswer property and/or Answer’s parentItem property to relate these two items.

So for a short question it could look like:

<section itemscope itemtype="http://schema.org/Question">
  <h2 itemprop="name text">My Question</h2>
  <div itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <p itemprop="text">My Answer</p>
  </div>
</section>


来源:https://stackoverflow.com/questions/27213736/right-way-to-set-microdata-for-qa-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!