XML technologies / XML / Perl & XML / Introduction to XML / Well-formed documents and free-form XML

(Excerpt from "Perl & XML" by Erik T. Ray & Jason McIntosh)

XML’s grandfather SGML required every element and attribute to be described by a correct declaration in the DTD. We explain this in more detail in the next section. For now, imagine filling in a form rather than writing a document. This form considerably increases the SGML processor’s workload, a major reason SGML did not become established on the Internet. HTML, originally developed as an SGML application, was also hampered by this requirement because every valid HTML document had to conform to the HTML DTD. Extending the language required a committee’s approval.

XML sets these constraints aside and permits free-form XML. In this mode, an XML document needs to meet only minimal syntax rules to be acceptable. An XML document following these minimal rules is called well-formed. These relaxed checks are wonderfully liberating for programmers. You do not always need to read the DTD just to make a small change. The processor only checks the simplest requirements.

In free-form XML, you choose element names yourself instead of following a fixed vocabulary as in HTML. Taking liberties with structure is risky, but if you know what you are doing, nobody objects. If you distrust the markup, however, introduce element and attribute declarations to enforce a structure, as described in the next section.

What are these minimal rules? Here is a brief selection, without claiming complete precision:

There are further rules. For a deeper understanding of well-formedness you should therefore read a Introduction to XML or consult the official W3C specifications at http://www.w3.org/XML.

Ensure that a document is well-formed whenever you want to process it with XML processors. In a sense, XML that is not well-formed does not exist. You can check this with a dedicated tool called a well-formedness checker, a kind of XML parser that reports errors when necessary. Its output is often very precise, normally giving the exact line and column of a problem. In XML basics: reading and writing we will examine checkers and parsers in more detail.

  

  

 

 

 

back to top