In the first example, Microdata analyzers only recognize that there is a Question and Answer element without any additional content. Microdata does not indicate that you need to consider the contents of HTML elements with itemscope attributes; it only cares about property values .
Testing your example with Microdata Online Analyzers :
name vs. text
For this very question, name will be "The correct way to set microdata for Q & A HTML", and text will be the body of the question ("Let's say one has a simple question ...").
If the whole question consists only of such a single short string, Id uses the text property instead of name (*). name can basically also be something like "Question 1" if you want / need it.
But you can also use both properties for a short question, i.e. itemprop="name text" , but it may not be very elegant (but it may make sense, especially if you know that some data consumer uses the name property).
* The example for Answer also uses text (and does not have a name ).
You can also use the suggestedAnswer property questions and / or the parentItem property answers to link the two elements.
So for a short question, it might look like this:
<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>
source share