When should I use "xml:" in front of some attributes?

Asked

Viewed 115 times

4

I noticed that some attributes use xml: for example xml:lang="pt-BR"? It seems to me to be an attribute, but it is neither local nor global. In HTML5, its use is required?

<html xml:lang="pt-BR">

</html>

1 answer

4


You do not need the prefix "xml" unless you want to treat your document simultaneously as XML and HTML decument. (I don’t recommend this - I think it’s best to just follow the HTML5 specifications)

To html tag specification suggests using a lang attribute with no xml prefix:

Authors are encouraged to specify a lang attribute on the root html element, Giving the Document’s language. This aids Speech Synthesis tools to determine what pronunciations to use, Translation tools to determine what Rules to use, and so Forth.


We encourage authors to specify a lang attribute in the root html element, with the language of the document. This helps speech synthesis tools to know which pronunciation to use, translation tools to know which rules to use, etc.

To specification of attribute lang goes deeper and says that you must use the attribute without the prefix xml:. If you want to maintain XML / XHTML compatibility (something that is usually not necessary) you should use both the lang as to the xml:lang.

Authors must not use the lang attribute in the XML namespace on HTML Elements in HTML Documents. To Ease Migration to and from XHTML, Authors may specify an attribute in no namespace with no prefix and with the literal localname "xml:lang" on HTML Elements in HTML Documents, but such Attributes must only be specified if a lang attribute in no namespace is also specified, and Both Attributes must have the same value when Compared in an ASCII case-insensitive Manner.

Note: The attribute in no namespace with no prefix and with the literal localname "xml:lang" has no Effect on language Processing.


Authors should not use the lang attribute in the XML namespace on HTML elements in HTML documents. To facilitate migration to and from XHTML, authors can specify an attribute without namespace with the literal name xml:lang but these attributes can only be used if an attribute without the namespace is also specified, containing the same value.

Note: the attribute with name xml:lang without specifying the prefix xml has no effect on language processing.

  • Just to make the information clear and complete for beginners: this prefix "xml:" in the current context is called Metadata?

  • 1

    "Metadata" is a vague term but I’ve never seen it used that way.

  • How long I don’t see you responding, always with a great +1 response

  • 1

    ah, thank you :>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.