Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does XML have such verbose closing tags? [closed]

Tags:

xml

verbosity

Yes, this probably shouldn't bug me.

But it does!!

Why does XML have such verbose closing tags? Not only does it make documents uglier for humans, it needlessly introduces the risk of mismatched (or misspelled!) opening and closing tags.

Even if we wanted to require closing tags, why do we need to include the name of the opening tag inside the closing tag? There is never any ambiguity in XML, because innermost tags must be closed before closing outer tags!

For example:

<thisIsSomewhatLong>
    Hello, world!
</thisIsSomewhatLong>

...is so much more verbose than:

<thisIsSomewhatLong>
    Hello, world!
</>

And it doesn't resolve any ambiguity, either for humans or for computers.

Does anyone know what the rationale is for this rule? What risks are avoided by disallowing empty closing tags?

like image 668
ClosureCowboy Avatar asked Dec 06 '10 20:12

ClosureCowboy


People also ask

Does XML require closing tag?

All XML elements must have a closing tag.

Is XML verbose?

Raw XML is indeed verbose, but its general simplicity has made it a building block of so many improvements in technical communication that its use endures and even flourishes to this day.

How should an XML file end?

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.

What is a self closing element?

Self Closing HTML ElementsSome HTML tags (like img and br ) don't have their own content. These are known as self closing tags or empty tags. They look like this: A simple example: <br /> The br tag inserts a line break (not a paragraph break).


1 Answers

Because it improves readability, XML was born not to be efficient or concise, just to be easy to work with.. and if you think having </> wouldn't create ambiguities it is just because you are indenting the code. If you leave out indentation (which is a really weaker constraint compared to having the name in a closing tag) then it becomes a mess.

A simple example?

<A><B><C><D>foo</><D>bar</></><H>baz</></></>

You think it's so readable? It's hard to understand where <H> is without counting closing tags..

like image 109
Jack Avatar answered Oct 14 '22 19:10

Jack