XML Syntax

XML syntax refers to the rules that determine how an XML application can be written. The XML syntax is very straight forward, and this makes XML very easy to learn. Below are the main points to remember when creating XML documents.

Well-formedness

The W3C specifies that all XML documents must be well-formed. Specifically, a textual object is a well-formed XML document if:

If this all sounds confusing, don't worry too much. Basically, all you need to do is ensure you build your XML applications correctly!

XML Declaration

If you include an XML declaration, it must be the first item in your document. The XML declaration uses the <?xml?> element.

Example:

One Root Element Only

Each XML document must have one root element and no more. All other elements must be contained within the root element.

Example:

XML Markup

Generally speaking, an XML document consists of markup and data.

Markup is provided in the form of tags and attributes. Data is the text that goes in between the tags or is provided within their attributes.

The next couple of lessons cover the key syntax rules related to elements and attributes.