Sams Teach Yourself XML in 21 Days

Sams Teach Yourself XML in 21 Days

By Steven Holzner

Creating Well-Formed XML Documents

What does it mean for an XML document to be well-formed? Formally, it means that the document must follow the syntax rules specified for XML by the W3C in the XML 1.0 recommendation or the XML 1.1 candidate recommendation. Although there are a fair number of requirements for a document to be well-formed, informally, the main requirements are that the document must contain one or more elements, and one element, the root element, must contain all the other elements. In addition, each element must nest inside any enclosing elements properly.

Here's an example of a nesting error—this document is not well-formed because the </heading> closing tag comes after the <message> opening tag, mixing up the <heading> and <message> elements:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="ch01_04.css"?>
<document>
    <heading>

           Hello From XML

       <message>

       </heading>

           This is an XML document!

       </message>
</document>

Creating well-formed documents is what Day 3, "Creating Well-Formed XML Documents," is all about.

Share ThisShare This

Informit Network