Page 12 of 28PREVNEXT

XML: What's it all about?

Rule Example
One tag must contain all other tags. In other words, your data file must have a root element. The previous section discussed root elements <cat> <name>Izzy</name> </cat>             
If you provide an opening tag, you must provide a closing tag (with the exception of empty tags, which we explain below). <cat> ... </cat>             
All opening and closing tags must match.

Correct

<cat> ... </cat>

Incorrect

<cat> ... </Cat>
Some tags, called empty tags, do not require closing tags because they include the closing forward slash as part of the tag. The example shows tags for inserting a horizontal rule and a line break.

Horizontal rule

<hr/>

Line break

<br/>
You must enclose all attribute values in single or double quotation marks.

Correct

patient_id="389467"

Incorrect

patient_id=389467
All tags must be nested correctly. The sequence of closing tags must mirror the sequence of opening tags.

Correct

<cat> <name>Izzy</name> </cat>

Incorrect

<cat> <name>Izzy</cat> </name>
All entities must be declared. Now don't panic. An entity is a virtual storage area. It can contain images, text, or characters such as the copyright symbol. Here are the entities for the copyright symbol and each angle bracket. &copy; © &lt; < &gt; >
The basic rules for creating well-formed XML.

You may hear the phrase "well-formed XML" and wonder what that means. It's simple: XML is well-formed when it follows a small set of strict rules.

For example, XML is case sensitive. It cares about capital letters. For XML data to be well-formed, the tags must all use an identical mix of capital letters and small letters. So <CAT> ... </CAT> is well-formed, but <CAT> ... </Cat> is not.

You don't have to know all the rules, but if you'd like to know them, they're listed in this table. Here's what you do have to know: You can share XML data among users and systems only when that data is well-formed. If it is not well-formed, your XML system stops working (which means that your business stops working).

But that's a good thing. Really. Because, if a block of XML data is not well-formed, chances are that it's also corrupt. XML's innate ability to alert you early can save you from a variety of later problems, such as having to correct inaccurate numbers in your reports or clean corrupted data out of your files.

In the practice session, you'll violate one of the rules for well-formed XML and see how Word 2003 handles that error.

Page 12 of 28PREVNEXT