XML, like HTML, can be written using any text editor or word processor. There are also many XML editors that have been created since the first edition of this book. These editors have various capabilities, such as validating your XML as you type (see Appendix A).
Figure 1.1. An XML document describing one of the Seven Wonders of the World: the Colossus of Rhodes. The document contains the name of the wonder, as well as its location and its height in feet.
Figure 1.2. Here I am extending the XML document in Figure 1.1 above to support multiple <wonder> elements. This is done by creating a new root element <ancient_wonders> which will contain as many <wonder> elements as desired. Now, the XML document contains information about the Colossus of Rhodes along with the Great Pyramid of Giza, which is located in Giza, Egypt, and is 455 feet tall.
Figure 1.3. In a well-formed XML document, there must be one element (wonder) that contains all other elements. This is called the root element. The first line of an XML document is an exception because it’s a processing instruction and not part of the XML data.
Figure 1.4. Every element must be enclosed by matching tags such as the name element. Empty elements like main_image can have an all-in-one opening and closing tag with a final slash. Notice that all elements are properly nested; that is, none are overlapping.
Figure 1.6. The quotation marks are required. They can be single or double, as long as they match each other. Note that the value of the file attribute doesn’t necessarily refer to an image; it could just as easily say “The picture from last summer’s vacation”.
You can add extra white space, including line breaks, around the elements in your XML code to make it easier to edit and view (Figure 1.9). While extra white space is visible in the file and when passed to other applications, it is ignored by the XML processor, just as it is with HTML in a browser.
Figure 1.9. The wonder element shown here contains three other elements (name, location, and height), but it has no text of its own. The name, location and height elements contain text, but no other elements. The height element is the only element that has an attribute. Notice also that I’ve added extra white space (green, in this illustration), to make the code easier to read.