Extensible Markup Language (XML) Tutorial

Well Formed XML Documents

A well formed document ensures the tags do not overlap and has closing tags for each open tag.

Overlapping Tags

XML has a strict hierarchical syntax. Tags must be nested properly by closing all child elements before closing the parent elements. The following is an example of an overlapping tag in HTML.

An Incorrect HML Document with Overlapping Tags

<u><b>This is underlined and BOLD</u></b>

As the bold tag is started within the underline tag, it should be closed before the underline tag. Browsers are able to render the above line so that it displays correctly, but this would be illegal in XML as it doesn't adhere to the strict hierarchical syntax.

Corrected Example

<u><b>This is underlined and BOLD</b></u>

SGML doesn't require closing tags, but XML does to ensure the well-formedness of the document. Some HTML tags don't have closing tags. To adhere to the rules of XML, an XHTML document works around the problem by placing a '/' at the end of the tag.

<img src="images/logo.gif" alt="Logo" width="100" height="50" />

Case Sensitive

XML is case sensitive. XHTML, the XML version of HTML is defined in lowercase. All tags and attributes should be declared in lowercase.

Quotes

Attribute values should always be placed in single or double quotes, regardless of the data type, as in the following example.

<table border="0" cellpadding="0" cellspacing="0">

You might also like...

Comments

About the author

Gez Lemon United Kingdom

I'm available for contract work. Please visit Juicify for details.

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook