Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

Nine Rules for Creating Good XML

  • Print
  • + Share This
  • 💬 Discuss
From the author of
HTML allows you to be a little lax, but XML is a sterner taskmaster. James J. Maivald and Cathy Palmer have come up with nine simple rules that will help you to create well-formed XML every time.

HTML is a forgiving language. It tolerates a host of sins, from imprecise markup to altogether missing elements, and can still generate a web page in the browser. XML, on the other hand, is basically a tyrant. Violate even the most trivial rule, and the browser or your application will crash. Some people find comfort in the uncompromising nature of XML, because it won’t work unless you build it correctly. It’s great to get instant feedback when you do something wrong!

There are nine basic rules for building good XML:

  1. All XML must have a root element.
  2. All tags must be closed.
  3. All tags must be properly nested.
  4. Tag names have strict limits.
  5. Tag names are case sensitive.
  6. Tag names cannot contain spaces.
  7. Attribute values must appear within quotes ("").
  8. White space is preserved.
  9. HTML tags should be avoided (optional).

XML that follows these rules is said to be "well formed." But don’t confuse well-formed XML with valid XML!

Now let’s look at the rules with some examples.

Rule 1: All XML Must Have a Root Element

A root element is simply a set of tags that contains your XML content.

<root>
  <author>Ernest Hemingway</author>
  <author>John Steinbeck</author>
  <author>James Joyce</author>
</root>
  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus