Chapter 2. Well-Formed XML

Chapter 1 discussed some of the reasons why XML makes sense for communicating data, so now it's time to get your hands dirty and learn how to create your own XML documents. This chapter covers all you need to know to create well-formed XML. Well-formed XML is XML that meets certain syntactical rules outlined in the XML 1.0 recommendation.

This chapter includes the following:

  • How to create XML elements using start-tags and end-tags

  • How to further describe elements with attributes

  • How to declare your document as being XML

  • How to send instructions to applications that are processing the XML document

  • Which characters aren't allowed in XML—and how to use them in your documents anyway!

Because the syntax rules for XML and HTML are so similar, and because you may already be familiar with HTML, we'll be making comparisons between the two languages in this chapter. However, if you don't have any knowledge of HTML, you shouldn't find it hard to follow along.

If you have Microsoft Internet Explorer 5 or later, you may find it useful to save some of the examples in this chapter on your hard drive and view the results in the browser. If you don't have IE5 or later, some of the examples include screenshots to show what the results look like. One nice advantage of doing this is that the browser will indicate whether you make a syntax mistake. I do this quite often, to ensure I haven't mistyped anything.

The examples given in this chapter are also available for download from the ...

Get Beginning XML, 4th Edition 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.