|Lesson 3||Rules for a well-formed XML document|
|Objective||List Rules for constructing well-formed XML documents. |
Rules for constructing well-formed XML Documents
Wel-formedness is essential in XML. The W3C instructs us that violations of well-formedness constraints are fatal errors.
Documents that are not well-formed will not load in a browser or will not be processed by an XML parser, according to the XML Recommendation.
Five rules for well-formed documents
An empty element must be closed with
Empty elements may be used for elements that have no content.
You may be familiar with the
empty tags from HTML.
In HTML, empty tags are not required to have closing tag in the form />. In XML, empty elements must be closed with
. For example
- XML elements that have name-value pair attributes must enclose attribute values in single or double quotation marks.
In this example, the
element has an attribute named
with the value
Note that the attribute value is enclosed in double quotation marks for the document to be well-formed.
- XML elements must nest and un-nest in reverse order.
For example, the following XML document is not well-formed because it violates the rule for correctly nesting elements:
The correct nesting of these elements would be:
Well Formed XML Document
The next lesson shows you how to determine the inherent structure of information within XML documents.