Library tutorials & articles

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">

Comments

  1. 19 Jan 2006 at 14:16

    Beutiful article. Takes a user from a beginner level to an intermediate level very nicely. Certainly a treat for beginers and an expert alike.

  2. 04 Apr 2004 at 22:28

    Good article for starters

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Extensible Markup Language (XML) Tutorial.

Leave a comment

Sign in or Join us (it's free).

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

Related discussion

Related podcasts

  • LINQ to XML

    Scott's been poking around with LINQ to XML and reports his findings to Carl about life with XDocuments and XElements. They also talk about the bridge classes that link (no pun intended) System.Xml and System.Xml.Linq.

We'd love to hear what you think! Submit ideas or give us feedback