Mote Interactive

Tags and Simple XML Tutorial

Tags

To learn HTML, XHTML and XML you'll need to know a little something about tags. When web browsers load a page they move from the first tag to the next tag and display it's contents until the page is loaded. This is an example of a tag:

<table>

Tags are words that start with an open angle bracket, have a word in the middle and end with a close angle bracket. Tags tend to have an opening tag like the one above and a closing tag (like the one below). Anything inside those tags are the contents of that tag:

</table>

A closing tag is usually the same word with a backslash (/) in front of it.

This is a valid tag set:

<title>Tags and XML</title>

You can have nested tags, like this example:

<head>
<title>Tags and XML</title>
</head>

But you can't mix the order of the tags, like this:

<head>
<title>Tags and XML</head></title>

You can also do without the closing tag in some cases.

<title />

But you still need that closing backslash.

 

XML Tags

Building XML (eXtensible Markup Language) is more strict than building HTML (Hyper Text Markup Language). Browsers were built to adapt to the laxness of HTML programmers, but XML is intended for more structured data exchange. XML's rules are stricter, but worth learning. Someday HTML will be obsolete and replaced with the more standards-compliant XHTML (which borrows much of the strictness of XML).

An XML tag starts with an angle bracket and then a name.

<title

After this the bracket could be closed...

<title>

or left open and some attributes of that tag could be included inside that tag:

<title author="Richard Wright">Native Son</title>

In this example, the word "author" is an attribute of the "title" tag. Attributes always have values, in this case the value of "author" is "Richard Wright". In XML attributes must be followed by an equals sign and then the value must be enclosed in quotes.

This is not valid XML, because there are no quotes around the attribute value:

<title author=Martha Ostenso>Wild Geese</title>

You might notice in this example that quotes serve to mark the beginning and ending of the value of the author attribute. In this incorrect example the value of author might be mistaken as "Martha" and the word "Ostenso" becomes an attribute without a value.

This example below is also not valid, since tag names can't have values.

<title="Wild Geese"></title>

>>>MORE XML and HTML
MORE TUTORIALS