X hits on this document





15 / 142

A gentle introduction to XML markup

<html> <head> <title>Hello, World</title> </head> <body> <p>Hello, World</p> </body> </html>

This document structure should look familiar to you. It is a valid XML document, and it only contains a single root element, namely html. There are then two branches to the document, head and body.

Element names are case-sensitive

Element names, the basic vocabulary of XML documents, are case-sensitive. In Figure 2.1 there are five elements: html, head, title, body, and p. Since each element's name is case-sensitive, the element html does not equal HTML, nor does it equal HTmL or Html. The same is true for the other elements.

Elements are always closed

Each element is denoted by opening and closing brackets, the less than sign (<) and greater than sign (>), respectively. XML elements are rarely empty; they are usually used to provide some sort of mean- ing or context to some data, and consequently, XML elements usually surround data. Each of the ele- ments is Figure 2.1 are opened and closed. For example, the title of the document is denoted with the <title> and </title> elements and the only paragraph of the document is denoted with <p> and </p> ele- ments. An opened element does not contain the initial forward slash but closing elements do.

Sometimes elements can be empty such as the break tag in XHTML. In such cases the element is opened and closed at the same time, and it is encoded like this: <br />.

Elements must be correctly nested

Consecutive XML elements may not be opened and then closed without closing the elements that were opened last first. Doing so is called improper nesting. Take the following incorrect encoding of an XHTML paragraph:

<p>This is a test. This is a test of the <em> <strong>Emergency</em> Broadcast System.</strong></p>

In the example above the em and strong elements are opened, but the em element is closed before the strong element. Since the strong element was opened after the em element it must be closed before the em element. Here is correct markup:

<p>This is a test. This is a test of the <strong> <em>Emergency</em> Broadcast System.</strong></p>


Document info
Document views328
Page views334
Page last viewedThu Oct 27 09:16:02 UTC 2016