Reply to Re: Why use a /> at the end of a statement?

Your name:

Reply:


Posted by Jukka K. Korpela on 03/03/07 19:52

Scripsit Steve Pugh:

> It's required in XHTML. Why? Because one of the restrictions of XML
> over SGML and hence of XHTML over HTML is that all elements must be
> expclitl closed.

It's somewhat debatable whether the "/" is quite explit.

> Which means both that all those optional closing tags
> like </p> and </li> become mandatory, and that empty elements must
> close themselves and the XML syntax for that is <br />.

Actually, empty elements close themselves just as well in SGML. They just
don't use the "/". When an element has EMPTY declared content, the element
cannot have content and cannot have an end tag, so the start tag is the
entire element. It's "self-closing", so to say.

This is no different in XML, except that since XML is to be processed by
simple tools that possibly don't read any DTDs (so that they cannot know
which elements have EMPTY declared content, among other things), XML has
rules that ensure that a document can be parsed as a sequence of tags and
content strings without knowing anything about any higher level syntax.
Hilariously, people often praise XML for being "more structural".

So the point is that when an SGML parser sees <br>, it needs to check the
document type definition to see that the element cannot have any content,
whereas an XML parser needs a low-level indicator, <br />. Actually <br />
is equivalent to <br></br>, though the longer form is frowned upon for
"compatibility" reasons. Web browsers that eat HTML are expected to skip the
"/" in "<br />" (not really because they process SGML but rather because
they don't - instead they have simplistic poor mans tag slurper parsers that
ignore the "/" just because they traditionally skip everything that they
don't understand).

Quite a mess, eh?

In practical terms, XHTML is pointless as a delivery format of WWW documents
for the time being. It's just an exercise in futility, though some day
things might change, in some direction.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация