What is XHTML and when should it be used?

Asked

Viewed 3,926 times

9

What I know is that XHTML needs to be valid XML. This implies, for example, that all tags need to be closed. For example:

Errado:
<br>

Certo:
<br/>

But what is the use of it? What is it for? When should it be used?

  • XHTML is the standard used in the construction of electronic books such as Amazon’s mobi and epub. Basically e-books follow this standard so that there is portability between devices.

3 answers

5


Basically XHTML is a reworking of HTML based on XML, with all its rules and validations.

What is the use? Some devices do not recognize HTML, as it has no semantic meaning.

When should it be used? If you want your application to be seen everywhere (TV, LM, mobile, etc), XHTML is the right way.

  • 2

    Currently Xhtml is embedded in HTML5 which is the default to be followed.

  • @Marceloaymone, are you saying that I can use JSF with HTML5 instead of XHTML?

  • JSF 2.2 already has yes support. http://www.codigosfontes.com.br/jsf-2-html-5-jquery-bootstrap-15-minutes/

4

XHTML is HTML written according to XML rules. Since XML is much stricter than HTML, the idea is that you write a syntax without errors. XML is a very generic markup language. Unlike HTML, XML allows you to make your own tags. Today, this doesn’t make much sense anymore since we have other ways of structuring data, such as JSON, for example.

And that was the big download: a XHTML file is an HTML and also an XML. That means that data extraction would be much easier. Imagine that you could extract data from any web page as if you were requesting an XML file. Interesting, but not very useful at the time. Another thing is that for a XHTML to be really useful, it needs to be served with the application/xhtml+xml Mimetype, which no one did. When HTML5 came into being, by rebelling a group of developers linked to several browsers, the scenario changed a lot. HTML5 actually solved some problems we had years ago in web development.

However, since HTML5 is fully backwards compatible, you can use your XHTML today as if it were normal HTML. The syntax of XHTML will not break your website and you will be trouble-free. Today, no one uses XHTML, so there is no indication or suggestion for you to use in your projects.

2

Another application of XHTML is dynamic content generation. You can, for example, interpret with Javascript an XML file that represents a part of a page. Large access web applications use this strategy to take advantage of cache. For example: the menu, which is something that doesn’t change often, can be rendered dynamically by a Javascript from a mix of CSS and XHTML, where the XHTML portion is in a file .xml and the formatting in a .css. In this situation it is possible to force the cache of these two files on browser, saving expensive resources such as internet links and on-line processing web server.

If you can, watch this presentation: https://skillsmatter.com/skillscasts/1939-asynchronous-systems-architecture-for-the-web English is relatively easy and the speaker is Udi Dahan, an architect. Net recognized worldwide. It’s worth it!

  • Never touched me about it! Thanks for sharing.

  • Good tip! + 1 :)

Browser other questions tagged

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