2

Can someone explain to me what a markup language is? Why XML is a markup language and why YAML and JSON are not?

I've read many articles but none of those are giving any kind of examples. If someone can help me to understand this with some examples, that'd be great!

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Healthy Bowl
  • 191
  • 1
  • 9
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Sep 28 '21 at 19:53

2 Answers2

3

The purpose of markup languages such as XML is to represent documents, whereas the purpose of data serialization languages such as YAML or JSON is to represent data. Examples follow:

XML

<document>
  <paragraph>This is a <i>small</i> document</paragraph>
<document>

YAML

customer:
    first_name: John
    last_name:  Smith
    dob:        2000-01-01

JSON

{
  "customer":
    {
      "first_name": "John"
      "last_name": "Smith"
      "dob": "2000-01-01"
    }
}

Historically, there has been plenty of cross-over use, but originally as well as currently, the document vs data distinction best characterizes the difference.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Hi @kjhughes Thank you so much for giving examples. Can you help me with what do you mean by representing documents? And, How XML differs from HTML? – Healthy Bowl Sep 21 '21 at 13:39
  • The provided examples already illustrate the concept representing documents (vs representing data). XML/HTML difference: HTML represents web page documents via a fixed set of tags (`html`, `body`, `div`, `p`, `b`, etc). XML represents documents in general and allows for the creation of new tags. (Historical note: XHTML defined HTML tags in XML.) – kjhughes Sep 21 '21 at 14:06
  • We can do the same with XML also whatever we're doing with YAML right? Then how do they both differ? – Healthy Bowl Sep 21 '21 at 14:09
  • The difference between XML and YAML has already been presented via explanation, example, and links for further reading. – kjhughes Sep 21 '21 at 15:01
2

The term "markup" originates with the hand-written marks used by copy editors (human beings) to indicate changes that need to be made to a text, or styling to be applied to the text (such as italics, justification, or paragraph breaks). See for example https://www.pinterest.co.uk/pin/407927678731145164/ Typically these are instructions to the type-setter (also a human being!) who would be responsible for creating first galley proofs and then final paginated copy.

The essence of markup is therefore annotating a text to supply editorial meta-information for use in preparing final copy. SGML, XML, and HTML are firmly in that tradition.

Use of XML as a data transfer syntax was another way of applying the same technology, but it's not what markup was designed for. JSON and YAML work well as a data transfer syntax, but they don't work well for annotating texts.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164