Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are XML/HTML tag names inside closing tags really necessary?

This is really not a programming question per se, but I was wondering why the name of the tag is required in a closing tag in XML. For instance, couldn't

<a>
    <b>stuff</b>
</a>

Be written

<a>
    <b>stuff</>
</>

So that each closing tag </> merely terminated the last opened tag?

So my questions are

  1. Would this work (i.e. are there any corner cases I'm not thinking of in which this would be ambiguous/fail)?
  2. If it would work, why didn't 'they' design it that way?
like image 856
Seth Carnegie Avatar asked Jul 22 '11 03:07

Seth Carnegie


People also ask

Is closing tag necessary in XML?

All XML elements must have a closing tag.

Is HTML closing tag necessary?

TL;DR: In HTML5 it is not strictly necessary to close certain HTML tags.

What is closing tag of XML?

The end tag functions exactly like a right parenthesis or a closing quotation mark or a right curly brace. It contains no data of its own; it simply ends the most recent (innermost) tag with the same name. XML requires a matching end tag for each start tag.


1 Answers

If it would work, why didn't 'they' design it that way?

One reason is that SGML/XML are also designed to be human readable. Your /a/b example is readable, but a structure much more complex would be a nightmare to try to interpret.

This would especially be true with mixed content (PCDATA and element structures mixed).

like image 179
Daniel Haley Avatar answered Sep 27 '22 19:09

Daniel Haley