Quantcast

Error in documentation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Error in documentation

Oliver
The documentation contains the following statement:

"
How can I use Thymeleaf for HTML5 if it is an XML-based technology?
You can because HTML5 allows non-XML-formed code only for legacy compatibility reasons, and HTML5 code can be (in fact, should be) well-formed XML.
"

The opposite is true. There is no relation between HTML and XML. At best you can regard them as siblings. Developers are actually encouraged to write HTML, **not** XML. XHTML was intended to be an XML version of HTML, but HTML 5 deliberately and explicitly abandoned that idea.

So does Thymeleaf support HTML or not?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error in documentation

Zemi
Administrator
Hello Oliver,

Yes, Thymeleaf supports all kind of markup, as HTML and XML or even plain text.

Writing HTML as XML makes easier for automated agents to understand the pages so it can help, for example, with your page SEO, so I would definitely recommend to write HTML as XML.

Kind regards,
  Zemi
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error in documentation

danielfernandez
Administrator
In reply to this post by Oliver
Thymeleaf supports HTML4 and HTML5. Besides, Thymeleaf 3.0 is no longer an XML-based technology and now parses HTML5 natively... that FAQ item definitely needs to be changed, thanks for pointing it out.

As for the relation between HTML5 and XML-based syntax, this is a actually quite common misconception. Please let me explain...

HTML and XML are in their base incompatible languages because none of them can be expressed as an application of the other, but the idea of HTML5 is to go beyond that and serve as an evolution for both HTML4 and XHTML 1.1. So HTML5 is compatible with HTML4's syntax, but it is also compatible with XHTML's syntax, and so HTML5 code can also be expressed in XML-ized syntax. That's actually one of the key features of HTML5: allowing legacy integration of both HTML4 and XHTML code without (almost) any changes at all --- most usually only the DOCTYPE clause.

For example, I invite you to go to https://validator.w3.org/#validate_by_input and input the following document:

-----------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>something</title></head>
<body>
  <form action="#"><div><input name="whatever" /><br /></div></form>
</body>
</html>
-----------

You will see how, having HTML4 been selected via DOCTYPE, the validator gives you warning about those "input" and "br" tags being minimized or "self-closing" (i.e. " />"), with the text:

"To avoid the messages, simply remove the "/" character in such contexts. NB: If you expect <FOO /> to be interpreted as an XML-compatible "self-closing" tag, then you need to use XHTML or HTML5."

And indeed, if you replace the DOCTYPE from the example above with "<!DOCTYPE html>" so that it is validated as HTML5, no errors or warnings will be issued.

As for developers being encouraged to write HTML not XML, I suppose you mean they are encouraged to write HTML5, not XHTML, which is true. But as I say, HTML5 does allow XML-style syntax (closing all tags, quotes around attribute values, etc.). And this kind of syntax provides advantages in terms of parsing ease and structure for development tools and the like. Besides being IMHO more human-readable, machine-processing XML-style code is much, much easier and much less error-prone than making code that adequately understands HTML4, so why not use the more integrable and processable syntax? ;)

Regards,
Daniel.
Loading...