XML syntax overview

XML syntax rules are simple but strict. For this reason, creating software that can read and use XML is easy.

Refer to the following example of an XML document.

<?xml version= “1.0” encoding=“ISO-8859-1”?>
<note>
<to>Dick</to>
<from>Jane</from>
<heading>Notice</heading>
<body>See Spot run!</body>
</note>

The first line in the document is the XML declaration. It defines the XML version and the character encoding that is used in the document. In this case, the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin-1/West European) character set. The XML declaration is not a part of the XML document itself, and therefore does not require a closing tag.

The next line describes the root element of the document. In this example, it is saying, “This document is a note.”

The next four lines describe the four child elements of the root: to, from, heading, and body (each of which has start and end tags).

The last line defines the end of the root element: </note>.

Writing comments in XML

Use the following syntax for writing comments in XML.

<!-- This is a comment -->