Anatomy of an XML Document
The best way to explain how an XML document is composed is to present one. Example A-1 shows an XML document you might use to describe two authors.
Example A-1. A very simple XML document
<?xml version="1.0" encoding="us-ascii"?> <authors> <person id="lear"> <name>Edward Lear</name> <nationality>British</nationality> </person> <person id="asimov"> <name>Isaac Asimov</name> <nationality>American</nationality> </person> <person id="mysteryperson"/> </authors>
The first line of the document is known as the XML declaration. This tells a processing application which version of XML you are using—the version indicator is mandatory—and which character encoding you have used for the document. In this example, the document is encoded in ASCII. (The significance of character encoding is covered later in this appendix.)
If the XML declaration is omitted, a processor will make certain assumptions about your document. In particular, it will expect it to be encoded in UTF-8, an encoding of the Unicode character set. However, it is best to use the XML declaration wherever possible, both to avoid confusion over the character encoding and to indicate to processors which version of XML you’re using. (1.0 is most common, but 1.1, which makes relatively minor though potentially incompatible changes, has recently appeared.) Encoding handling should be automatic with Office, but you may need to watch for documents you import from other sources.
Elements and Attributes
The ...
Get Office 2003 XML now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.