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?
All XML elements must have a closing tag.
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.
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.
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).
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With