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.
The W3C specifies that all XML documents must be well-formed. Specifically, a textual object is a well-formed XML document if:
- Taken as a whole, it matches the production labeled document
- It meets all the well-formedness constraints given the XML specification
- Each of the parsed entities which is referenced directly or indirectly within the document is well-formed
If this all sounds confusing, don't worry too much. Basically, all you need to do is ensure you build your XML applications correctly!
If you include an XML declaration, it must be the first item in your document. The XML declaration uses the
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.
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.