Beginning XML: Basic Syntax and Differences From HTML
XML is the acronym
for Extensible Markup Language, which focuses on describing data and what data
also a markup language, but it deals with how data looks and is
tags are not predefined like HTML tags – you must invent your own. XML
physically do anything; rather, it helps to structure, store, and send
information across different information systems in an easy, simple way
doesn't require any translation at all.
The first line of an XML document, called the XML declaration, is optional. It gives the version of XML currently being used (either 1.0 or 1.1, although 1.0 is the most common), as well as the character encoding.
The rest of an XML document invariably contains nested elements, or pairs of tags, inserted throughout. Each element is comprised of one pair of tags, called a start tag and an end tag. The start tag is formed by putting a term in angle brackets. The end tag is formed in the same way as the start tag, using the same term, except this time there is a slash directly after the first angle bracket and before the term.
Example start terms:
between the <rule> and
</rule>, start and end tags in the example above, is considered
content. A full element has a start tag, content, and an end tag, just
Besides text content, an XML element may also include attributes. An attribute is a name and a value paired together, placed in the start tag directly after the element name.
**Keep in mind that although the number 1 is a quantity and that the term technical is a measurement of quality, in XML they are merely supposed to stand for the terms they describe, not function as the terms themselves.
The values of attributes must
be put in
either single or double quotes. In the above example, the “
Elements can include other elements inside of them.
In this example, the element termlist contains three term elements. The element termlist is also known as the top-level root element, or document element. XML that does not contain a top-level root element is formed badly, and is considered malformed.
Incorrect XML Example:
XML is different than HTML in many subtle but crucial ways, so it follows that there are some tasks that are better suited for XML than HTML, and vice versa – for instance, with XML it is a much simpler task to access crucial document information than with HTML, which would sometimes require an excess of so-called markup language red tape.
HTML doesn't have to have a closing tag, but XML does (except in the case of the XML declaration, which is not considered an element, so the usual rules don't apply).
Example of correct XML:
HTML tags can be used in
(or nested improperly), but XML tags need to be used exactly
without overlapping (or nested properly).
This is fine for
HTML, but the <i>
tags overlap with the <b> tags, so as XML, the above markup
HTML tags get rid of any white space purposely included in a document, whereas XML preserves all white space.
With these basic tenements of the syntax of XML and its differences from HTML under your belt, you should have a firm idea of how to create and use basic, valid XML.