Home > Articles > Web Services > XML

  • Print
  • + Share This

Four Common Errors

The XML syntax is very strict: Elements must have both a start and end tag, or they must use the special empty element tag; attribute values must be fully quoted; there can be only one top-level element; and so on.

A strict syntax was a design goal for XML. The browser vendors asked for it. HTML is very lenient, and HTML browsers accept anything that looks vaguely like HTML. It might have helped with the early adoption of HTML but now it is a problem.

Studies estimate that more than 50% of the code in a browser deals with errors or the sloppiness of HTML authors. Consequently, an HTML browser is difficult to write, it has slowed competition, and it makes for mega-downloads.

It is expected that in the future, people will increasingly rely on PDAs (Personal Digital Assistants like the PalmPilot) or portable phones to access the Web. These devices don't have the resources to accommodate a complex syntax or megabyte browsers.

In short, making XML stricter meant making simplifying the work of the programmers and that translates into more competition, more XML tools, smaller tools that fit in smaller devices, and, hopefully, faster tools.

Yet it means that you have to be very careful about what you write. This is particularly true if you are used to writing HTML documents. In this section, I review the four most common errors in writing XML code.

Forget End Tags

For reasons explained previously, end tags are mandatory (except for empty elements). The XML processor would reject the following because street and country have no end tags:

   <street>34 Fountain Square Plaza 

Forget that XML Is Case-Sensitive

XML names are case sensitive. The following two elements are different for XML. The first one is a "tel" element whereas the second one is a "TEL" element:


A popular variation on this error is to use a different case in the opening and closing tag of an element:


Introduce Spaces in the Name of Element

It is illegal to introduce spaces in the name of elements. The XML processor interprets spaces as the beginning of an attribute. The following example is not valid because address book has a space in it:

<address book>
      <name>John Doe</name> 
      <email href="mailto:jdoe@emailaholic.com"/> 
</address book>

Forget the Quotes for Attribute Value

Unlike HTML, XML forces you to quote attribute values. The following is not acceptable:

<tel preferred=true>513-744-8889</tel> 

A popular variation on this error is to forget the closing quote. The XML processor assumes that the content of the element is part of the attribute, which is guaranteed to produce funny results! The following is incorrect because the attribute has no closing quote:

<tel preferred="true>513-744-8889</tel> 
  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.