I list below all topic groups, which I have done according to subjects, which they handle. You can return to this topic group by using this menu and the link Table of topic groups on the top of the each page.
|Table of topic groups > Front page of CSS-guide > Guide pages > 1. What are basic structures of HTML and XML documents > XML and XHTML (section 7/7)|
XML has been born from the special needs of commercial
companies. HTML-elements are limited and they don't often
describe the matter itself. In XML documents can use
HTML-elements or create own elements, which are self-describing
Especially the purpose of Microsoft is to create large world-wide databases, which have the possibility to use elements and element patterns as searching criterion. Also mathematical science, chemistry could use own elements. Because there is no limits of possible elements, XML is extensible (eXtensible M arkup Language).
HTML documents have predefined presentations to elements. XML elements don't have any default presentation. Undefined XML element is just nothing! A way to give presentation to XML elements is CSS. If XML-documents use same elements as HTML-documents, the same CSS-file can be used in HTML and XML-documents (I made extra page about this matter).
Another way is XSL (eXtensible Stylesheet Language), which have more possibilities to affect to the structure of XML-document. Microsoft favors it. It gives the possibility to set elements in another order with more powerful way than CSS. It is however remarkable, that favoring XSL is partially derived from the truth that the CSS implementation in Microsoft Internet Explorer is not ready. CSS can't give proper presentation to XML document using MS IE browsers.
If the implementation would be better, the case would be different. Shortly - the CSS-implementation of MS IE doesn't fulfil XML-requirements. It is possible to create good presentation to XML documents for example for Netscape 6.x+ and Opera 4.x+ browsers. I handle MS IE 5.5+ in extra page).
The compatibility of XML-documents towards HTML 3.2 capable browsers is depending of the author of the XML document. In the worst case XML-document is to old browsers stick text with some special encoding (read the footnote 1, if you want to know, what I mean with special encoding) - in practice impossible or extremely difficult to read. In fact the author can create his own HTML resemblance language - XML is ideal language to "do-it-yourself " people! XML-document can however be quite readable to old browsers, when all or most elements are same as in the HTML-documents (they don't need however to behave at the same way in XML-capable browsers).
An XHTML (eXtensible Hyper Text M arkup Language) document is a special XML-document, which use primary the same elements as HTML-documents. It can be declared either as a HTML or XML document. But XHTML-document must always made according to XML rules, which are in some matters more strict than in HTML documents. First of all documents must be well-formed - it is not allowed to make as much encoding errors as before! Between ordinary HTML-documents and XHTML-documents are for example following differences:
Documents might have the XML-declaration (
<?xml ...?>), but it is not required. HTML-documents don't have at all corresponding declaration. Like HTML-documents XHTML-documents must declare as XHTML-document with standard DTD-information, for example
<!DOCTYPE HTML PUBLIC "-//w3c//dtd xhtml 1.0
"http://www.w3.org/TR/xhtml1/"/dtd/transitional.dtd"> (in the strict DTD-document type
is a tiny error - read the footnote 2).
The root element is always
and there is XML namespace declaration:
All HTML-elements and attributes are written in lower
case characters. All elements are in XML-documents
case sensitive. This kind of combination is illegal
in XML-documents even it is valid in HTML-documents:
<BODY>... </body>. If attributes have standard values, they must write with lowercase characters (for example
All attribute values including those, which
have only numeric values must be inside
quotations. The attribute
width=3 is not
valid in XHTML-document. It must be
id-attributes are case sensitive (in addition it is worth to know that if for example for an
A element have been set an identifier it is not enough to set just a
name-attribute but instead or in addition of a
name-attribute must use also an
id-attribute, which has exactly the same value as the
Elements are divided more strictly into normal and
empty elements. Empty elements don't need in ordinary
HTML-documents any kind of closing tags. This is not however
valid procedure in XML-documents. Also empty elements needs some
kind of clear termination. The termination is marked before the
> -sign, for example
scr="image.gif" /> (when before the forward slash
/) is left a single space, all browsers can read
the tag correctly). Then the opening tag is at the same time the
termination tag. In HTML-document elements
LI don't need necessary termination tags even if
they are allowed (it is even recommended to give the termination tag for the
P - I use always termination tags to this
element). This is illegal in XHTML-documents. It is also illegal
to use in XML-documents
<p /> or
/>, because those elements are not as their nature
<!DOCTYPE HTML PUBLIC "-//w3c//dtd xhtml 1.0 transitional//en" http://www.w3.org/TR/xhtml1/"/DTD/transitional.dtd"> <html xmlns="http://www.w3.org/TR/xhtml1/"> <head> <meta name="keywords" content="Opera,Mozilla,Netscape,Internet Explorer,CSS" /> <title>An example XHTML document</title> </head> <body> <h1>The main header
</h1> <br /> <p>Text.
</p> <blockquote>Text inside a block quote
</blockquote> <ol> <li>Text in a list.
</li> <li>Text in a list.
</li> </ol> </body> </html>
Pages of this CSS-guide are today XHTML 1.0 documents except model pages. It is easy to convert HTML-files into XHTML-files using the HTML Tidy utility, which is HTML-Kit (freeware). If you want to use same CSS-files in HTML, XHTML and XML-document, it is sensible to write names of elements always with lower case characters. I have tried to create my examples so, that they could be used also in XHTML-documents. To use scripts is however problematic, but I have used them like in normal HTML-pages.W3C: XHTML 1.0 (4.8 Script and Style elements and C.4 Embedded Style Sheets and Scripts), Namespaces in XML.
The next page handle basic methods, how to use style sheets.
Footnote 1. DTD-files, which are used with XML-files are primary created according to the same principles as in HTML-files. Own common entities (commonly abbreviations) must be declared. It is recommended to use CDATA sections instead of common entities to express special encoding on the screen. If the author creates his own entities, the document is at some parts an-readable to old browsers. Old browsers can't know what own entities mean.
In the XHTML 1.0 Strict DTD-file is an erroneous
parameter entity declaration (
A like it does in the DTD-file for HTML
4.0 loose (
target %FrameTarget; #IMPLIED -- render in
this frame --).