An XML document must be contained in a single element

page 12 But an XML parser will throw an exception when it sees this document. If you want the same effect, you would need to code this: bI really, ireallyibi like XML.i

1.2.2.3 All attributes must be quoted

You can quote the attributes with either single quotes or double quotes. These two XML tags are equivalent: a href=http:www.oreilly.com a href=http:www.oreilly.com If you need to define an attribute with the value , you can use single quotes inside double quotes, as we just did. If you need both single and double quotes in an attribute, use the predefined entities quot; for double quotes and apos; for single quotes. One more note: XML doesnt allow attributes without values. In other words, HTML elements like ol compact arent valid in XML. To code this element in XML, youd have to give the attribute a value, as in ol compact=yes .

1.2.2.4 XML tags are case-sensitive

In HTML, h1 and H1 are the same. In XML, theyre not. If you try to end an h1 element with H1 , the parser will throw an exception.

1.2.2.5 All end tags are required

This is another area where most HTML documents break. Your browser doesnt care whether you dont have a p or br tag, but your XML parser does.

1.2.2.6 Empty tags can contain the end marker

In other words, these two XML fragments are identical: lily age=6lily lily age=6 Notice that there is nothing, not even whitespace, between the start tag and the end tag in the first example; thats what makes this an empty tag.

1.2.2.7 XML declarations

Some XML documents begin with an XML declaration. An XML declaration is a line similar to this: ?xml version=1.0 encoding=ISO-8859-1? If no encoding is specified, the XML parser assumes youre using UTF-8, a Unicode standard that uses different numbers of bytes to represent virtually every character and ideograph from the worlds languages. Be aware that each parser supports a different set of encodings, so you need to check your parsers documentation to find out what your options are.

1.2.2.8 Document Type Definitions DTDs and XML Schemas

All of the rules weve discussed so far apply to all XML documents. In addition, you can use DTDs and Schemas to define other constraints for your XML documents. DTDs and Schemas are metalanguages that let you define the characteristics of an XML vocabulary. For example, you might want to specify that any XML document describing a purchase order must begin with a po element, and the po element in turn contains a customer-id element, one or