Go to previous pageGo to next page

1.3.2. XML Tags

All XML elements must have a closing tag

With XML it is illegal to omit the closing tag. As you perhaps know in HTML some elements do not have a closing tag such as e.g. "<p>". The following code is legal in HTML:

Legal HTML CodeLegal HTML Code

In XML however, all elements have a closing tag, like this:

Legal XML CodeLegal XML Codeimportant

You might have noticed from the previous example that the XML declaration (<?xml version="1.0" encoding="ISO-8859-1"?>) did not have a closing tag. This is not an error. The declaration is not a part of the XML document itself. It is not an XML element, and it therefore does not need a closing tag.

All XML elements must be properly nested

All XML elements must be properly nested within each other: you are not allowed to close an XML tag until other tags that are enclosed by that tag (so called childs), are closed as well:

Tag nestingTag nesting

XML tags are case sensitive

Opening and closing tags must be written with the same case. The tag <message> is different from the tag <Message>:

Tags are case sensitiveTags are case sensitive

All XML documents must have a root element

All XML documents must contain a single tag pair to define a root element. The name of the root element must appear once in an XML document. All other elements must be within this root element. All elements can have sub elements (child elements). Sub elements must be correctly nested within their parent element:

Root element and its childrenRoot element and its children

By expanding our address example with the root element <person> we get the same structure as above (root, child, subchild).

Expanded address exampleExpanded address example

Comments in XML

The syntax for writing comments in XML is:

Comments in XMLComments in XML


Go to previous page
Go to next page