7

There are those tags which have immediate effect (< br >) and those which affect what is between them ( < a > < / a > ).

Closing tag is verbose, and I believe also redundant:

<tag parameters> ... </tag>

verbose

Compare to LISP's s-expresions.

(tag parameters)

redundant

Ending tags are not even necessary. These language are context-free and this is not possible there:

<tag1> <tag2> </tag1> </tag2>

Basically these should be equivalent:

<tag1> <tag2> </> </>
<tag1> <tag2> </tag2> </tag1>       

questions

Are ending tags there to aid readability? What is purpose of redundancy in closing tags? I want to understand inside the logic behind desing of this. Thanks. :)

4
  • 2
    Your example: <tag1> <tag2> </> </> is nice when you only have 1 line. Think of a file that 10M and you have a missing close tag. How do you identify which one is missing. Oct 27, 2011 at 15:16
  • 1
    @Loki True.:) I see Your point, but doing such file by hand?
    – user712092
    Oct 28, 2011 at 16:54
  • @Loki Offtopic: Imagine it would be <tag1 <tag2 >>, so for example <tag1 some huge amount of text <tag2 another huge amount > third huge amount > fourth huge amount. You can jump from beginning to the end of such tag, in editors who support it (in Vim, it is just by %, so it is very easy thing). Parameters, for they must be there and they must not break previous rule, might be then something like <tag #parameters # text and tags enclosed> ...
    – user712092
    Oct 28, 2011 at 17:08
  • 1
    Though you may use tool and special editors to build your basic HTML document they always very general and I always end up finishing the editing by hand editing the HTML. Oct 28, 2011 at 17:40

3 Answers 3

11

In the case of XML, Tim Bray outlines the design goals in his annotated version of the XML spec http://www.xml.com/axml/target.html#sec-origin-goals.

The design goals for XML are:

  1. XML shall be straightforwardly usable over the Internet.
  2. XML shall support a wide variety of applications.
  3. XML shall be compatible with SGML.
  4. It shall be easy to write programs which process XML documents.
  5. The number of optional features in XML is to be kept to the absolute minimum, ideally zero.
  6. XML documents should be human-legible and reasonably clear.
  7. The XML design should be prepared quickly.
  8. The design of XML shall be formal and concise.
  9. XML documents shall be easy to create.
  10. Terseness in XML markup is of minimal importance.

The annotation for goal 10 is:

Terseness is of Minimal Importance

The historical reason for this goal is that the complexity and difficulty of SGML was greatly increased by its use of minimization, i.e. the omission of pieces of markup, in the interest of terseness. In the case of XML, whenever there was a conflict between conciseness and clarity, clarity won.

Rick Jelliffe has some more background in http://www.oreillynet.com/xml/blog/2008/01/the_design_goals_of_xml_1.html

0
13

In your question title, you ask about HTML, SGML and XML as if they are the same thing, but they are not. In fact, they are very different in precisely that area which you are asking about.

In particular, SGML has both Null End Tags and Implied End Tags (and Implied Elements as well), and since HTML is an application of SGML, it inherits those.

Null End Tags allow you to leave out the name of the End Tag. Instead of

<tag>content</tag>

You can also write

<tag/content/

Implied End Tags allow you to leave out the End Tag altogether, if it is clear from the context that there must be an End Tag. For example, in HTML, a body element cannot be inside a title or head element, therefore you can write

<html>
  <head>
    <title>The Title
  <body>

and both the title and head elements will be implicitly closed.

End Tags are also implied at the end of the document: all elements will be closed in reverse order.

With Implied Elements, you can leave out both Start and End Tags: since p is only allowed within body, the first p will imply a body:

<html>
  <head>
    <title>The Title
    <p>

Here, there is a body element in the document, even though there are no body tags.

Putting it all together, you get something like this:

<HTML /
  <HEAD /
    <TITLE / > /
    <P / >

This is a complete, 100% well-formed, 100% valid HTML document. (Well, it's missing the DOCTYPE declaration, but if you add one, you can run it through the W3C validator as HTML 1.0, 2.0, 3.2 and 4.01, even as Strict.)

It is semantically equivalent to the following XHTML:

<html>
  <head>
    <title>
      &gt;
    </title>
  </head>
  <body>
    <p>
      &gt;
    </p>
  </body>
</html>

Now, which one of the two is easier to read? (Actually, that's a serious question. I'm particularly interested in what seasoned Lisp programmers have to say.)

3

Yes, ending tags are there to aid readability and clarity in case of error. If a document is malformed and missing an end-tag, how would the developer be sure which tag is missing?

Also, I suspect that having the name in the end-tag aids in SAX-type parsing, allowing the parser to easily identify the type of node that is being ended.

1
  • Thank You. :) Could You please just find a source for it?
    – user712092
    Oct 26, 2011 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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