In short. RDFa uses datatype for a literal's datatype and lang or xml:lang for its language.
Definition: RDFa uses literal attributes on an element with a
propertyto describe the value emitted in the RDF statement.datatypeidentifies the literal's datatype, while a host-language attribute such aslangorxml:langsupplies language information.
Key facts
- The W3C RDFa 1.1 Primer uses
datatype="xsd:gYear"to make the value2011an explicitly typed year. - The Primer maps
xsd:gYeartohttp://www.w3.org/2001/XMLSchema#gYearand lists booleans, integers, dates, and doubles among the standard datatype examples. - RDFa Core 1.1 defines
datatypeas an attribute that expresses the datatype of a literal. - RDFa Core identifies
@xml:langand@langas host-language mechanisms for adding a language tag to a plain literal.
What does datatype change?
An element carrying property can produce a literal from its text. The Primer shows a copyright year with an explicit datatype:
<span property="dc:date" datatype="xsd:gYear">2011</span>
The xsd prefix is one of RDFa's default prefixes in that example. Its value expands to the XML Schema datatype IRI for gYear, so a processor can represent the literal as a year rather than leaving the string's intended type implicit. The Primer explains that the datatype gives processors information that helps them choose a suitable representation for values such as years and integers.
RDFa Core defines the value of datatype as a term, CURIE, or absolute IRI representing a datatype. The attribute therefore names the datatype through the same RDFa IRI mechanisms used elsewhere in the markup. Its syntax is separate from the vocabulary term in property: property identifies the predicate, and datatype describes the literal object.
How does RDFa mark a language?
Language marking is supplied by the host language. RDFa Core states that XHTML+RDFa can use either xml:lang or lang, whether the literal comes from content or from inline text. For example:
<meta about="http://example.org/node"
property="ex:property" xml:lang="fr" content="chat" />
This describes the literal chat with the French language tag. The specification also says that a language value can be inherited. An ancestor such as an html element can therefore provide the language for a descendant property element when the descendant supplies no different language value.
The distinction is visible in RDF's literal forms: a language-tagged plain literal carries a tag such as @fr, while a typed literal carries a datatype IRI. The RDFa attributes section groups datatype, content, xml:lang, and lang under literal attributes.
Which text becomes the literal value?
content lets the machine-readable value differ from the text shown to readers. The Primer describes it as overriding the default use of textual content. RDFa Core gives the processing rule: the literal is the content value when that attribute is present; otherwise it is the concatenation of descendant text in document order. The current language information is included with a plain literal when a language is in effect.
The following pattern keeps a readable date on the page while exposing an ISO date and an explicit datatype:
<span property="dc:modified"
content="2015-09-16T16:00:00-05:00"
datatype="xsd:dateTime">16 September 2015</span>
When markup inside a value is present only for rendering, RDFa Core documents an empty datatype value as a way to produce a plain literal. The intended result then comes from the element's text content.
How can a site owner check the markup?
Inspect each literal property in the delivered HTML. First identify the predicate in property. Then check whether the machine-readable value is supplied by content, whether datatype names the intended datatype, and whether lang or xml:lang supplies or inherits the intended language. Compare the attribute value with the displayed text in cases such as the Primer's ISO date example, where the two forms are deliberately different.
Related terms
- RDFa
- How does RDFa content provide a machine-readable property value?
- How can JSON-LD distinguish a typed date from plain text?
- HTML lang attribute
FAQ
Is lang an RDFa-only attribute?
No. RDFa Core describes lang and xml:lang as mechanisms supplied by the host language. RDFa uses the resulting language information when it creates a plain literal.
Can the displayed text differ from the RDFa value?
Yes. Put the machine-readable value in content. RDFa Core gives that value precedence over element content, while the Primer shows a readable date paired with an ISO date value.
What should datatype contain?
It should identify the intended datatype through a term, CURIE, or absolute IRI. The Primer's xsd:gYear example expands to the XML Schema gYear IRI.
Sources
- W3C, "RDFa 1.1 Primer - Third Edition", 17 March 2015
- W3C, "RDFa Core 1.1 - Third Edition", 17 March 2015
Check how a page reads to answer engines. Open the GEO score analyzer