0

What's the difference between HTML and XML?

I'm well familiar with HTML, but my knowlege about XML very limited.

In old-fashioned HTML we were forced to write something like:

<div>
  <p>Hi</p>
</div>

In other words, in HTML we have limited set of tags.

Unlike XML, where we can specify our own tags:

<letter>
  <to>John</to>
  <from>Mike</from>
  <date>01.01.2017<date>
  <contents>Hi!</contents>
</letter>

However, now I have Chrome installed on my computer, and it's history page looks like this:

<body>
  <history-app>
    <history-router>...</history-router>
    <history-toolbar>...</history-toolbar>
    <div>
      <history-side-bar>...</history-side-bar>
      <iron-pages>...</iron-pages>
    </div>
  </history-app>
</body>

As you can see, there are a lot of tags, which are not exist in HTML.

The same case with AngularJS, where we can create our own custom tags.

So I'm a bit confused is there any real difference between XML and HTML in modern times.

Also, maybe (I'm not sure, because as I said, my knowledge about XML is very limited), XML provides some rules (schemes) about how tags can and can not be organized. For example, I have some scheme called "Standard Letter", and according to this scheme, tag <letter> should always contain tags <to> and <from>, and moreover, <to> must be the first. Hm... but HTML also has such requirements. For example, <table> always must have <tr> inside, and <td> inside <tr>.

Previously, I've asked about difference between DocBook and HTML. But I've also decided to reformulate it in a new manner, as described above (XML vs. HTML).

Community
  • 1
  • 1
john c. j.
  • 725
  • 5
  • 28
  • 81
  • http://courses.cs.vt.edu/~cs1204/XML/htmlVxml.html – Pete Mar 07 '17 at 16:52
  • Although there is certainly some relation (there was XHTML, a version of HTML that was XML as well) the question per-se doesn't really make more sense than asking what's the difference between Paris and London. I have the impression that you're more interested in something specific: whether you can create your own HTML tags. – Álvaro González Mar 07 '17 at 16:55
  • 1
    This is far too broad of a question, and just a little bit of research can find the answer. Both are descended from SGML, a more generic markup language, so both use tags, attributes, etc.. Beyond that, there are many, many differences. – Heretic Monkey Mar 07 '17 at 16:57
  • @Pete, Thanks. I'm still doesn't understand the difference, but this article confirmed some of my own guesses (about the role of a sheme). – john c. j. Mar 07 '17 at 17:13

1 Answers1

4

HTML and XML are both markup languages that share a common heritage with an older markup language, SGML.

  • Use HTML (and CSS) when you wish to target presentation in web browser.
  • Use XML when you wish to define custom markup for documents. XML will allow a document to be marked up for what content is rather than for how content should look. Content can then be decoupled from its presentation, allowing content to be independently translated to different media such as web or print automatically.

(And use JSON when you wish to define custom data formats that are data rather than document oriented.)

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Ok, but *why* it's better to use XML for documents? What's the practical advantage? – john c. j. Mar 07 '17 at 17:20
  • Answer updated to explain that XML provides for markup according to *what content is* rather than *how content should look*. – kjhughes Mar 07 '17 at 17:24
  • I've upvoted your answer and I'm thankful for it, but separating content from presentation is a feature which is exist in *both* XML and HTML. It's not exclusive XML feature. – john c. j. Mar 07 '17 at 17:36
  • I did say to *use XML when you wish to define custom markup for documents*. I'm happy to educate, but if you're looking for an academic argument or extended discussion, this site isn't the proper venue. – kjhughes Mar 07 '17 at 18:40