104

I've been wondering why XML has an L in its name.

By itself, XML doesn't "do" anything. It's just a data storage format, not a language! Languages "do" things.

The way you get XML to "do" stuff, to turn it into a language proper, is to add xmlns attributes to its root element. Only then does it tell its environment what it's about.
One example is XHTML. It's active, it has links, hypertext, styles etc, all triggered by the xmlns. Without that, an XHTML file is just a bunch of data in markup nodes.

So why then is XML called a language? It doesn't describe anything, it doesn't interpret, it just is.

Edit: Maybe my question should have been broader. Since the answer is currently "because XML was named after SGML, which was named after GML, etc" the question should have been, why are markup languages (like XML) called languages?

Oh, and WRT the close votes: no, I'm not asking about the X. I'm asking about the L!

  • 128
    On what do you base your requirement that a language has to "do" something? I don't see that in any of the definitions at dictionary.com. – kdgregory Apr 3 '16 at 13:06
  • 10
    Just like Swahili is only understood if both understand it. Or a medical journal article is understood if the reader understands that part of the language. It's no different. And people make up the definitions. – Sami Kuhmonen Apr 3 '16 at 13:47
  • 42
    Markup language is a common term en.wikipedia.org/wiki/Markup_language – paparazzo Apr 3 '16 at 15:35
  • 37
    @MrLister: "Those are human languages, not computer languages" A language is a language. At its most extreme, even English requires contextual information (which dialect is being used) to understand unambiguously. Doesn't stop it from being a language. Your question simply has a false premise. – Lightness Races in Orbit Apr 3 '16 at 16:24
  • 68
    Languages don'rt do things, they express and communicate things – Hagen von Eitzen Apr 3 '16 at 20:42
238

The real answer is XML has an L in the name because a guy named Raymond Lorie was among the designers of the first "markup language" at IBM in the 1970'ies. The developers had to find a name for the language so they chose GML because it was the initials of the three developers (Goldfarb, Mosher and Lorie). They then created the backronym Generalized Markup Language.

This later became standardized as SGML (Standardized General Markup Language), and when XML was created, the developers wanted to retain the ML-postfix to indicate the family relationship to SGML, and they added the X in front because they thought it looked cool. (Even though it doesn't actually make sense - XML is a meta language which allows you to define extensible languages, but XML is not really extensible itself.)

As for your second question if XML can legitimately be called a language:

Any structured textual (or even binary) format which can be processed computationally can be called a language. A language doesn't "do" anything as such, but some software might process input in the language and "do" something based on it.

You note that XML is a "storage format" which is true, but a textual storage format can be called a language, these term are not mutually exclusive.

Programming languages are a subset of languages. E.g. HTML and CSS are languages but not programming languages, while JavaScript is a real programming language. That said, there is no formal definition of programming language either, and there is a large grey zone of languages which could be called either data formats or programming languages depending on your point of view.

Given this, XML is clearly a language. just not a programming language - though it can be used to define programming languages like XSLT.

Your point about namespaces is irrelevant. Namespaces are an optional feature of XML and do not change the semantics of an XML vocabulary. It is just needed to disambiguate element names if the format may contain multiple vocabularies.


Edit: reinierpost pointed out that you might have meant something different with the question than what I understood. Maybe you meant that specific vocabularies like XHTML, RSS, XSLT etc. are languages because they associate elements and attributes with particular semantics, but the XML standard itself does not define any semantics for specific elements and attributes, so it does not feel like a "real language".

My answer to this would be that XML does define both syntax and semantics, it just defines it at a different level. For example it defines the syntax of elements and attributes and rules about how to process them. XML is a "metalanguage" which is still a kind of language (just like metadata is still data!). As an example EBNF is also clearly a language, but its purpose is to define the syntax of other languages, so it is also a metalanguage.

  • 33
    There is a formal definition of a language in computing. – user22815 Apr 3 '16 at 18:01
  • 19
    @Snowman: A "formal language" does not necessarily correspond to what is usually called a language in computing. For example a "formal language" does not need to be textual - machine code is as a formal language as is most binary formats and protocols. So I wouldn't say the term "formal language" covers the same meaning as "language" in computing. – JacquesB Apr 3 '16 at 18:14
  • 15
    I am not aware of any requirement that a language needs to be textual or not be textual. The idea of constructing a sentence from terminals has nothing to do with an arbitrary interpretation of the bits in those terminals, or which types of computers (silicon or carbon-based) are capable of reading them. – user22815 Apr 3 '16 at 18:16
  • 4
    @NicolBolas: Good point, machine code is definitely a language. I just think it is more common to call binary languages "formats", e.g. you say the GIF-format not the GIF-language. – JacquesB Apr 4 '16 at 7:25
  • 3
    @BenCottrell: Wouldn't it be a graph then, since is may have loops? – JacquesB Apr 4 '16 at 13:05
181

Because it is a language. A markup language, not a programming language.

Notice that natural human languages like English and Spanish don't "do" anything either. In fact, technically C++ and Java and the like don't "do" anything until they're fed into a compiler and the output gets executed. Doing stuff and being a language are largely orthogonal to each other.

  • 43
    Substitute "interpreter" for "compiler". Being fed to a compiler doesn't make them "do" anything, either, it just translates them into a different language, which, again, doesn't "do" anything. All execution is interpretation. Sometimes, the interpreter might be extremely simple and implemented in silicon, in which case we call it an "execution unit", but it's still an interpreter. </nitpick> Anyway, good answer! – Jörg W Mittag Apr 3 '16 at 19:00
  • 8
    @JörgWMittag Good point. Since I randomly chose languages that are normally compiled, added "and the output gets executed". – Ixrec Apr 3 '16 at 19:02
  • 1
    An extensible markup language, if you will. – doppelgreener Apr 4 '16 at 5:58
  • 1
    I'd argue that human languages do "do" things. See Speech-Act Theory... – Ray Apr 4 '16 at 14:53
  • 2
    Sweet, sweet orthogonality. Execute the language in a different algebra, and a whole new set of actions unfolds. Under theory, anyway. – Kenogu Labz Apr 4 '16 at 21:28
104

Let Σ be a non-empty, finite set of symbols, called an alphabet. Then Σ* is the countable infinite set of finite words that can be formed by concatenating zero or more symbols from Σ. Any well-defined subset L ⊆ Σ* is a language.

Let's apply this to XML. Its alphabet is the Unicode character set U, which is non-empty and finite. Not every concatenation of zero or more Unicode characters is a well-formed XML document, for example, the string

<tag> soup &; not <//good>

is clearly not. The subset XML ⊂ U* that forms well-formed XML documents is decidable (or “recursive”). There exists a machine (algorithm or computer program) that takes as input any word wU* and after a finite amount of time, outputs either 1 if w ∈ XML and 0 otherwise. Such an algorithm is a sub-routine of any XML processing software. Not all languages are decidable. For example, the set of valid C programs that terminate in a finite amount of time, is not (this is known as the halting problem). When one designs a new language, an important decision to make is whether it should be as powerful as possible or whether the expressiveness would better be restricted in favor of decidability.

Some languages can be defined by means of a grammar that is said to produce the language. A grammar consists of

  • a finite set of literals (also called terminal symbols),
  • a disjoint finite set of variables of the grammar (also called non-terminal symbols),
  • a distinguished starting symbol, taken from the set of variables and
  • a finite set of rules (so-called productions) that allow certain kinds of replacements.

Any word that consists exclusively of literals and can be derived by starting with the starting symbol and then applying the given rules belongs to the language produced by the grammar.

For example, the following grammar (in rather informal notation) lets you derive exactly the integers in decimal notation.

  1. The literals of the grammar are the digits 1, 2, 3, 4, 5, 6, 7, 8, 9, and 0.
  2. The variables are the symbols S and D.
  3. S is the starting symbol.
  4. Any occurrence of the variable S may be replaced
    • with the literal 0 or
    • by any of the literals other than 0 followed by the variable D.
  5. Any occurrence of the variable D may be replaced
    • by any of the literals followed by another instance of the variable D or
    • by the empty string.

Here is how we derive 42:

S —(apply rule 4, 2nd variant)→ 4 D —(apply rule 5, 1st variant)→ 42 D —(apply rule 5, 2nd variant)→ 42.

Depending on how elaborate rules you allow in your grammar, differently sophisticated machines are required to prove that a given word can actually be produced by the grammar. The example given above is a regular grammar, which is the most simple and least powerful. The next powerful class of grammars are called context-free. These grammars are also very simple to verify. XML (unless I'm overlooking some obscure feature I'm not aware of) can be described by a context-free grammar. The classification of grammars forms the Chomsky Hierarchy of grammars (and therefore languages). Every language that can be described by a grammar is at least semi-decidable (or “recursively enumerable”). That is, there exists a machine that, given a word that actually belongs to the language, derives a proof that it can be produced by the grammar within finite time, and will never output a wrong proof. Such a machine is called a verifier. Note that the machine may never halt when given a word that doesn't actually belong to the language. Clearly, we want our programming languages be described by less powerful grammars for the benefit of being able to reject invalid programs within finite time.

Schemata are an addition to XML that allow refining the set of well-formed documents. A well-formed document that follows a certain schema is called valid according to that schema. For example, the string

<?xml version="1.0" encoding="utf-8" ?>
<root>all evil</root>

is a well-formed XML document but not a valid XHTML document. There exists schemata for XHTML, SVG, XSLT and what not else. Schema validation can also be done by an algorithm that is guaranteed to halt after finite amount of steps for every input. Such a program is called a validator or a validating parser. Schemata are defined by so-called scema definition languages, which are a way to formally define grammars. XSD is the official schema-definition language for XML and is, itself, XML-based. RELAX NG is a more elegant, much simpler and slightly less powerful alternative to XSD.

Because you can define your own schemata, XML is called an extensible language, which is the origin of the “X” in “XML”.

You can define a set of rules that gives XML documents an interpretation as descriptions of computer programs. XSLT, mentioned earlier, is an example of such a programming language built with XML. More generally, you can serialize the abstract syntax tree of almost any programming language quite naturally into XML, if this is what you want.

  • 7
    @Giorgio: In mathematics, "well-defined" is largely just an intensifier: everything that mathematically exists is already well-defined. – Kevin Apr 3 '16 at 21:01
  • 9
    @Giorgio With “well-defined” I mean that there is a formal predicate that tells whether an item belongs to the set or not. This predicate will in general not be computable but it has to be clearly specified without contradiction. Otherwise, bad things might happen. “The pairs of strings (w, M) where M is the smallest description of a Turing machine that outputs w and then halts” is a well-defined but non-computable (see Kolmogorov complexity) predicate. … – 5gon12eder Apr 3 '16 at 21:02
  • 2
    @5gon12eder: That set does not exist under ZFC (because the axiom schema of separation is not powerful enough to describe it); if you're using some other set theory, you should specify it. – Kevin Apr 3 '16 at 21:03
  • 5
    @5gon12eder: “The set containing all strings that are not contained in the set” does not exist. The term "well-defined" is ironically not well-defined. – Kevin Apr 3 '16 at 21:09
  • 3
    The well-formed property or validation is performed by a grammar. This answer had been perfect if you had mentioned that. – Thibault D. Apr 6 '16 at 8:10
31

In computer science, formal language is just a set of strings, usually infinite and often described using rules (two common versions of those rules are regular expressions and formal grammars).

Note that this means that all a language needs is syntax, language doesn't need to describe what each valid string means (that's called semantics).

Now, this means that programming languages are formal languages that also have semantics, which describes some computation. And for example XHTML is a formal language, whose semantics describe (roughly and informally) how a hypertext document looks and behaves.

XML is still a language, even though it doesn't have semantics itself (but many languages derived from XML do, like XHTML and XAML).

Technically, binary formats are also languages, but they're not called that way. The term "language" is reserved for human-readable formats.

  • 10
    @MrLister Because they're not human-readable. When they aren't human-readable we tend to call them formats or data formats instead. – Mason Wheeler Apr 3 '16 at 13:43
  • 3
    @JamesSnell Not to be confused with the other ML language family, of course. Yay for over-crowded acronyms! – Mason Wheeler Apr 3 '16 at 14:07
  • 3
    If one is using formal tools to build a parser (or especially a validator) for JFIF etc. than the engineers may indeed refer to it as a "language". More likely though as a "grammar". – JDługosz Apr 3 '16 at 20:24
  • 3
    @MrLister: Well, they are languages, but because they define reusable data structures they have a special name: formats. But, yes, these are languages too. – Lightness Races in Orbit Apr 4 '16 at 0:58
  • 4
    @MrLister: Naming a format is more a question of marketing. The XML people called XML for XML because "*ML" indicates a family relationship to predecessor format like GML and SGML, and because they thought it looked cool with an X in the front. And GML was called GML because it was a generalized markup language, but also because it was the initials of the three language designers. So basically the L in XML is because a guy called Raymond Lorie was among the designers of the first markup language. – JacquesB Apr 4 '16 at 8:19
12

A language is a method of conveying information.

A programming language is a method of conveying algorithms.

A markup language like XML is a language for conveying data.

  • ... and that data may very well be a description of an algorithm. – Luaan Apr 5 '16 at 8:18
  • @Luaan ...and a programming language can also be abused to convey data. Like with JSON, for example. – Philipp Apr 5 '16 at 8:34
  • 2
    You can even recurse. I've seen NAnt scripts (an XML-based language) that contained C# code, which was only used for data storage. Using string literals that contained XML. Yes, it's the kind of thing that makes grown men cry :P – Luaan Apr 5 '16 at 8:43
2

XML is a meta-language. You use it to define specific languages. Languages never do anything, they just allow us to express things. Also, it is not true that XML is a "storage language". Just the opposite, in fact. You can store XML docs however you please. XML is better thought of as a transfer language. PS. If you don't think XML "does" anything, you'll have to explain how it is that many systems (e.g. jetty) use XML as a (bad) programming language. It's a lamentable abuse of XML, but it exists in the wild, and that just one of many examples.

protected by Thomas Owens Apr 4 '16 at 16:35

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.